• Post Reply Bookmark Topic Watch Topic
  • New Topic

autoboxing and autounboxing  RSS feed

 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what we have done here is autoboxing and autounboxing
but why we need to do that , i mean create a wrapper class and put that primitive value in the object and then use it with its reference
whats the catch here
i still didnt understand this ?
can you teach me ???

 
Paul Clapham
Sheriff
Posts: 22828
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to do that so that you can use an integer value in a context where only objects can be used. For example you might want to put integer values into an ArrayList.
 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:You need to do that so that you can use an integer value in a context where only objects can be used. For example you might want to put integer values into an ArrayList.

thanks but can you show me the use of it with one simple example please
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
List / ArrayList cannot store ints, only objects, so we use Integer.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!