[ 
https://issues.apache.org/jira/browse/GROOVY-7933?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15485289#comment-15485289
 ] 

Jose Ignacio Acin Pozo commented on GROOVY-7933:
------------------------------------------------

Fair enough. 

I always went my way by doing defensive coding to avoid these situations, so 
seeing now that there are two exceptions for "boolean" and "char" while the 
rest work correctly feels very confusing. 

I also think this should be documented somewhere very clearly, as the mantra 
"Groovy uses Objects for everything" is pretty much everywhere in 
documentation, with special mentions when talking about method resolution and 
primitives autowrapping. 

If this behaviour is changed to satisfy "boolean" and "char" primitives as 
well, then, the method resolution should be something like this: a(Boolean) > 
a(boolean) > a(Object). Primitives like Integer should be something like: 
a(Integer) > a(int) > a(Number) > a(Object). In summary: Unboxed > Boxed > More 
concrete subclass or implementation (if any) > Object. Am I correct?

> Incorrect boxing of boolean primitive types
> -------------------------------------------
>
>                 Key: GROOVY-7933
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7933
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 2.4.7
>            Reporter: Henri Tremblay
>
> A boolean primitive type seems to be boxed for no apparent reason. See the 
> example below. The problem disappear when using @CompileStatic or if 
> explicitly casting to (boolean).
> {code:java}
> public class Demo {
>    public void a(boolean a){
>        System.out.println("boolean was called");
>    }
>    public void a(Object a){
>        System.out.println("Object was called");
>    }
> }
> class Groovy {
>    static void main(String[] args) {
>        def demo = new Demo()
>        demo.a(true)
>    }
> }
> {code}
> *Output:*
> Object was called



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

Reply via email to