File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes class wrappers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "class wrappers" Watch "class wrappers" New topic
Author

class wrappers

Cristian Negresco
Ranch Hand

Joined: Sep 15, 2001
Posts: 182
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

Joined: Sep 29, 2000
Posts: 8521
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);


"JavaRanch, where the deer and the Certified play" - David O'Meara
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
wrapper class
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
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.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
...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"...
 
Consider Paul's rocket mass heater.
 
subject: class wrappers