Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overloading with Boxing and Var-args

 
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: 101
1
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic