Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is a "wrapper" class

 
Thomas Markl
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody explain what a wrapper class is and how we use it?
Thanks.
Thomas
 
Sayed Ibrahim Hashimi
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A wrapper class is a class that serves the sole purpose of holding something and adding some functionality to it.
In Java since the primitaves (like ints,floats,chars...) are not objects so if you want to treat them like one then you have to put use a wrapper class.
So lets say that i want to create a Vector of ints, the problem is a Vector only holds Objects not primitives. So what I will do is put all the ints in an Integer wrapper and use that. Example:

Hope this clears up some issues you are having.
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to add... here's an example of a wrapper class: java.lang.Integer.
[ July 30, 2002: Message edited by: Anthony Villanueva ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic