my dog learned polymorphism*
The moose likes Beginning Java and the fly likes boxing ,widening,var-args Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "boxing ,widening,var-args" Watch "boxing ,widening,var-args" New topic
Author

boxing ,widening,var-args

vini singh
Greenhorn

Joined: Dec 04, 2008
Posts: 18

output: DoX(s,s)=4 doX(7,7)=3

according to me doX(s,s) must be 3 i.e widen and then boxing then why its 4 i.e boxing and then widening.
[edit]Add code tags and disable smilies. CR[/edit]
[ December 06, 2008: Message edited by: Campbell Ritchie ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39062
    
  23
There isn't anything to widen to; the only thing that a short can be boxed to is Number (Short is a subclass of Number).

And please use the code tags; I have added them and you can see how much easier it is to read.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

A short can never be converted into an Integer, so all that remains is Short, Number or Object.

You can't widen then box, only box then widen


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
GeeCON Prague 2014
 
subject: boxing ,widening,var-args