• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Overloading with Boxing and Var-args

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 209
13
VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all for your replies
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic