• Post Reply Bookmark Topic Watch Topic
  • New Topic

Confused with Casting , Boxing concepts of Primitives and resp Wrappers  RSS feed

 
Dishi Jain
Ranch Hand
Posts: 46
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am so much confused with Casting and Boxing, UNboxing concepts of Primitives and respective Wrappers..
What all kinds of assignment will work?
What all kinds of operators will work?
What all operations (eg, equals() ) will work?
What all types of parameter passing will work?
What all are precautions?

Can anyone please summarize them at one place..Please please??

Thanks.
Dishi
 
Stephan van Hulst
Saloon Keeper
Posts: 7985
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can only assign primitives to their respective wrapper. Unboxing however is more permissive, you can assign any wrapper to a primitive, as long as the primitive is at least as precise as the type the wrapper represents.

So while you can not assign int to Long, you can assign Integer to long. Other than that, wrappers work exactly like other objects, so you can not assign Byte to Integer, because Byte is not a sub-type of Integer.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dishi Jain wrote:Can anyone please summarize them at one place..Please please??

I think Stephan's done that pretty well.

However, if you still find yourself confused, you do have another alternative: don't use them.

The wrapper classes all have explicit methods to do conversion to and from primitives; and I have to admit that I still use them quite a lot.

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!