Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Wrapper class

 
chad stevens
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone explain besides converting primitives to objects what a wrapper class is in more detail. I seem to be confused about this term when I read material that talks about advanced topics using wrapper classes.
 
Arun Boraiah
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apart from converting primitives to object wrapper class gives additional functionality which can't not be achieved by just
having it as primitives.
Like conversation of one type of primitives to another type.(int to double with out changing it's original value)
example

Integer oInt = new Integer(i);
..
..
double d = oInt.doubleValue();
Here you can see that orginal int value is retained.

An other important feature of wrapper class is converting string to int,long etc.
Also helps to convert to Octal, Binary, Hex decimal values.
 
chad stevens
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks your reply. I suppose my confusion came when I was reading something about Collections.
 
boyet silverio
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one use for wrapper classes is if, for some reason, you need to store primitive values into a Vector (say to take advantage of certain Vector functions) then you need to convert the primitives into objects before putting them into the Vector.
another is in web apps, where values, in order to be moved from one component (e.g. servlet) to another (e.g. page), need to be turned to objects (e.g. int 'wrapped' with Integer) before they are passed.
 
chad stevens
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Boyet.
Ah.. it seems to make more sense now with these examples! Thanks.
 
boyet silverio
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
welcome, nonetheless.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic