You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "John Wagenleitner (JIRA)" <ji...@apache.org> on 2017/08/24 20:10:00 UTC
[jira] [Updated] (GROOVY-7850) Documentation on primitives and
wrappers is misleading
[ https://issues.apache.org/jira/browse/GROOVY-7850?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
John Wagenleitner updated GROOVY-7850:
--------------------------------------
Component/s: Documentation
> Documentation on primitives and wrappers is misleading
> ------------------------------------------------------
>
> Key: GROOVY-7850
> URL: https://issues.apache.org/jira/browse/GROOVY-7850
> Project: Groovy
> Issue Type: Bug
> Components: Documentation
> 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
> Attachments: test1.groovy, test2.groovy, test3.groovy
>
>
> 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.4.14#64029)