• 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

Auto Boxing and Unboxing

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm not getting a clear picture about the contexts of auto-boxing and auto-unboxing.
Is auto-boxing and auto-unboxing will happen in line of the corresponding primitive types or there are some exceptions to this.
I mean following things are possible with primitive types:
a) Unary and Binary Numeric Promotion.
c) Narrowing and Widening conversions.
Does the above conversions apply when autboxing and auto-unboxing happen.
Can some one please clarify.
Thanks in adavance.
Regards,
Sharath
 
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
Autoboxing means converting a primitive type implicitly to an object (of one of the wrapper classes that corresponds to the primitive type that is converted), and autounboxing is ofcourse the opposite (implicitly converting an instance of a wrapper class to a primitive). These conversions are independent of promotions, narrowing and widening conversions, but ofcourse auto(un)boxing and the other conversions could be used together in one expression.

If you want to know the exact details, have a look at chapter 5 of The Java Language Specification, Conversions and Promotions. (Note, the JLS can be hard to read, but it is the official specification that describes everything into the finest details).
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic