Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

class wrappers

 
Cristian Negresco
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Could someone explain what the class wrappers are, when are they used, when not?
Does somebody know some usefull links?
BR,
Cristian
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, there are several kinds of wrappers.
The most common are primitive wrappers.
If you have a method or Collection that only accepts Objects then you can't feed in a primitive value. One way around this is to "wrap" the primitive value in an Object that just houses the value of the primitive.
class Integer just holds one value. That is the value of an integer. Then it has a bunch of methods to manipulate that integer so that it can be "handled" as an object.
ex:
Integer myInt = new Integer(3);
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wrapper class
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A wrapper class is an implementation of the Decorator Pattern. To learn more about what the Decorator Pattern is and why it's useful, take a look at the Structural Patterns section of James W. Cooper's The Design Patterns Java Companion.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...and I just ran across an article at JavaWorld that does an ok job of introducing the concept of patterns (including the decorator pattern): "Amaze your developer friends with design patterns"...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic