[
https://issues.apache.org/jira/browse/GROOVY-7933?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15485443#comment-15485443
]
John Wagenleitner commented on GROOVY-7933:
-------------------------------------------
{quote}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?{quote}
For Integer I believe the resolution is:
{{Integer > int > long > Long > BigInteger > float > Float > double > Double >
BigDecimal > Number > Object}}
However, there seems to be a difference between which of the first 2 are
resolved (Integer vs int) depending on where the call originates. For example,
if you run the following it will fail in the {{test()}} instance method
(sender/receiver are the same):
{code}
class Demo {
String a(int i) { 'int' }
String a(Integer bigI) { 'Integer' }
void test() {
String result = a(42)
assert result == 'Integer'
}
static void main(args) {
String result = new Demo().a(42)
assert result == 'Integer'
new Demo().test()
}
}
{code}
Sorry, getting a little off-topic for this particular reported issue, but this
doesn't seem right to me. This is not just the case for Integer but also for
the other boxed primitive types. It looks like GROOVY-7850 has noted this
inconsistency as well.
> 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)