widening and boxing - why isn't it allowed?

M

mluebeck

Hi everyone,

I'm trying to do widening and then boxing, but it's impossible. Can
anyone tell me the reason?
Why is that behaviour useful?

class WB {
static void go(Integer x) { System.out.println("Integer"); }
public static void main(String [] args) {
short s = 5;
go(s); // must widen then box - illegal. But why??
}
}

thanks for your answers!

Mario
 
H

Hemal Pandya

mluebeck said:
Hi everyone,

I'm trying to do widening and then boxing, but it's impossible. Can
anyone tell me the reason?
Why is that behaviour useful?

JLS 5.3 (Method Invocation Conversion) mentions that Method invocation
contexts allow the use of one of identity, widening primitive or
reference, boxing and unboxing conversion. Though it does not
specifically say so, this implies that more then one conversion is not
allowed.

No rationale is provided, but I assume it is to not further complicate
the already complex overload resolution rules.
class WB {
static void go(Integer x) { System.out.println("Integer"); }
public static void main(String [] args) {
short s = 5;
go(s); // must widen then box - illegal. But why??
}
}

thanks for your answers!

Mario
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,233
Latest member
AlyssaCrai

Latest Threads

Top