This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Overloading with Boxing and Var-args  RSS feed

 
Jia Ramharai
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 148
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for your replies
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!