Sebb created GROOVY-7850:
----------------------------

             Summary: Documentation on primitives and wrappers is misleading
                 Key: GROOVY-7850
                 URL: https://issues.apache.org/jira/browse/GROOVY-7850
             Project: Groovy
          Issue Type: Bug
    Affects Versions: 2.4.6
         Environment: Groovy Version: 2.4.6 JVM: 1.7.0_79 Vendor: Oracle 
Corporation OS: Mac OS X
            Reporter: Sebb


The doc [1] has the following example:

{code:title=test1.groovy}
int i
m(i)

void m(long l) {     // This is the method that Java would call, since widening 
has precedence over unboxing.
  println "in m(long)"
}

void m(Integer i) {     // This is the method Groovy actually calls, since all 
primitive references use their wrapper class.
  println "in m(Integer)"
}
{code}

Whilst the comment correctly identifies the method which is called by Groovy, 
it's somewhat misleading, since the code involves both widening and boxing.

The following code shows why:

{code:title=test2.groovy}
int i
m(i)

void m(int l) { // Groovy calls this method
  println "in m(int)"
}

void m(Integer i) {        
  println "in m(Integer)"
}
{code}

In the code sample above, Groovy does not autowrap the primitive int.

See also the following example:

{code:title=test3.groovy}
int i
m(i)

void m(long l) { // called by Groovy        
  println "in m(long)"
}

void m(Long i) {        
  println "in m(Long)"
}
{code}

This shows that Groovy widens rather than boxes.

So I think the statement "since all primitive references use their wrapper 
class." is at best misleading, and may be wrong.

[1] http://groovy-lang.org/differences.html#_primitives_and_wrappers




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

Reply via email to