• Post Reply Bookmark Topic Watch Topic
  • New Topic

autoboxing and unboxing  RSS feed

 
Ranch Hand
Posts: 234
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, i was wondering since these statement are valid:


is it because the first one unbox a Short wrap object to a short and the second one autoboxes a byte into a byte object?
I mean what seems strange to me is that we're effectively assigning an object to a primitive and a primitive to an object
thanks
 
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, auto boxing/unboxing is what that code demonstrates.
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, and yes.
 
Ranch Hand
Posts: 461
22
Android Chrome Eclipse IDE Google App Engine Java Notepad Oracle Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
compiler will do a job of autoboxing and unboxing during compilation.so even if you assign a primitive to its object equivalent reference,compiler will wrap that primitive and then assign it to that reference.
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is more information in the Java™ Tutorials and the Java® Language Specification (=JLS). Beware: the JLS can be difficult to read.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!