You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Frank Pavageau (JIRA)" <ji...@apache.org> on 2015/05/10 23:52:59 UTC

[jira] [Created] (GROOVY-7420) Cannot choose between primitive and object variants of an overloaded method

Frank Pavageau created GROOVY-7420:
--------------------------------------

             Summary: Cannot choose between primitive and object variants of an overloaded method
                 Key: GROOVY-7420
                 URL: https://issues.apache.org/jira/browse/GROOVY-7420
             Project: Groovy
          Issue Type: Bug
          Components: Static Type Checker
    Affects Versions: 2.4.3
            Reporter: Frank Pavageau
            Assignee: Cédric Champeau


The static type checked cannot choose which variant of a overloaded method with both primitive and object parameters (e.g. {{long}} and {{Long}}) to use when the actual type of the parameter is the object type (e.g. {{Long}}):

{code}
class A {
    static String m(long p) {
        "primitive"
    }

    static String m(Long p) {
        "object"
    }
}

Long l = 42L
A.m(l)
{code}
yields the following compilation error:
{noformat}
[Static type checking] - Reference to method is ambiguous. Cannot choose between [java.lang.String A#m(java.lang.Long), java.lang.String A#m(long)]
{noformat}

The problem can be worked around by explicitely calling {{.longValue()}} on the {{Long}}.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)