wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overloading with Boxing and Var-args Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overloading with Boxing and Var-args" Watch "Overloading with Boxing and Var-args" New topic
Author

Overloading with Boxing and Var-args

Jia Ramharai
Greenhorn

Joined: Feb 21, 2013
Posts: 5
Hello All,
Can you please help on the following 2 code snippets?



Output:
Byte, Byte
Because widening beats var-args



Output:
byte...
???

Why doesn't widening take place instead of var-args?

Thank you.
Richard Hayward
Ranch Hand

Joined: Feb 15, 2012
Posts: 68
    
    1
Hi Jia,

Jia Ramharai wrote:



Output:
Byte, Byte
Because widening beats var-args



This example does not demonstrate that widening beats var-args.
It shows that boxing beats var-args.

Jia Ramharai wrote:



Output:
byte...
???

Why doesn't widening take place instead of var-args?



It's not just widening that would be required.
There would have to be a widening from byte to integer, followed by boxing to Integer.
Seems this is asking too much of the compiler (K&B p252).

Regards
Richard
Zhenyi Luo
Ranch Hand

Joined: Sep 03, 2012
Posts: 33
Jia Ramharai wrote:Hello All,
Can you please help on the following 2 code snippets?



Output:
Byte, Byte
Because widening beats var-args



Output:
byte...
???

Why doesn't widening take place instead of var-args?

Thank you.


Because WidenAndBox is not allowed. On the other hand, though BoxAndWiden is allowed, trying to widen Byte to Integer will fail. Neither of them works.
Jia Ramharai
Greenhorn

Joined: Feb 21, 2013
Posts: 5
Thank you all for your replies
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Overloading with Boxing and Var-args