Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Wrapper Classes

 
Brett Delia
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some colleages and I were debating why the wrapper class that correspond with the primitive datatypes are immutable. I was hoping to get some feedback from this group as to why they are.

Thank in advance.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason why I think they are immutable is because of the purpose of these classes. If what I had read was correct, the purpose of these wrapper classes is so that you can store primitive values in Vectors and such. Since they all take Objects, but not primitives, there needed to be a way to put the primitives in them. SO they made the Wrapper classes. I also think they are used for statci methods for converting primitive types around.
I know I use them specifically for these two purposes. I always have to convert between pimitive and String and back and forth all the time.
For EJB's I 100% recommend always using the Wrapper Classes to map to database fields, rather than primitives. It just makes things easier.
Thanks
Mark
 
sanjays samadder
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
if you have done any bit of awt class you will notice that textcomponets take in dta in string format .the question is how will you convert them to primitive so as to perform calculations on them .in order to make them as primitive data type wrapper classes are used.that is one practical use i have found.
thanks
sanjay
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic