Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Ron McLeod
Paul Clapham
Tim Cooke
Devaka Cooray
Sheriffs:
Liutauras Vilda
paul wheaton
Rob Spoor
Saloon Keepers:
Tim Moores
Stephan van Hulst
Tim Holloway
Piet Souris
Mikalai Zaikin
Bartenders:
Carey Brown
Roland Mueller
Forum:
Beginning Java
boxing ,widening,var-args
vini singh
Greenhorn
Posts: 18
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
class Eggs { int doX(Long x,Long y){return 1;} int doX(long... x){return 2;} int doX(Integer x,Integer y){return 3;} int doX(Number n,Number m){return 4;} public static void main(String s[]) { new Eggs().go(); } void go(){ short s=7; System.out.println(doX(s,s)); System.out.println(doX(7,7)); }
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
Marshal
Posts: 79699
381
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Posts: 22800
131
I like...
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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 - OCEJPAD 6
How To Ask Questions
How To Answer Questions
It's hard to fight evil. The little things, like a nice sandwich, really helps. Right tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Boxing & Widening
boxing
Another question about Widening and Boxing
Question on widening ,boxing
Widening beats boxing?
More...