• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

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: 218
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
reply
    Bookmark Topic Watch Topic
  • New Topic