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

boxing

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


output: DoX(s,s)=4 doX(7,7)=3
as boxing is preffered against widening i think answer should be doX(s,s)=3 but then why its dox(s,s)=4 and the reason given is boxing and then widening as its a one step process. i really cant understand help me out please explain.what do they mean by one step process

(Jesper Young: Added code tags)
[ December 11, 2008: Message edited by: Jesper Young ]
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In compiler will chose because here short only need to be boxed to Short.Where in
compiler need to first widen then Box it to Integer.
So clearly choice one is prefferable.

[ December 10, 2008: Message edited by: subhasish nag ]
[ December 11, 2008: Message edited by: subhasish nag ]
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please use code tags when you post code - that will make it much easier to read.
 
subhasish nag
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jesper.
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by subhasish nag:
compiler need to first widen then Box it to Integer.
So clearly choice one is prefferable.



It's not about which is preferable. You CANNOT widen and then box. So these are illegal



But boxing and then widening is allowed. So these are legal

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic