• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A SIMPLE DOUBT REG WRAPPER CLASSES!

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HAI ALL,
WHAT IS THE USE OF MAKING A PRIMITIVE DATATYPE VALUE TO BE STORED IN A OBJECT AS WE STORE USING WRAPPER CLASSES!

I READ THAT IT WILL ADD FUNCTIONALITY!

CAN U EXPLAIN HOW IT WILL ADD FUNCTIONALITY & IS THERE ANY DRAWBACKS DUE TO THIS?

BYE FOR NOW!

CHEERS,
SAYEE
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,

WELCOME TO JAVARANCH!

HERE, LET ME HELP YOU WITH THAT "CAPS LOCK" KEY. SOMETIMES IF YOU BANG IT WITH YOUR FIST, LIKE THis, it comes unstuck. There! That's better!

I'm not quite sure what you're asking. In Java, the primitive types like "int", "char", "double", "boolean" aren't kinds of objects; as a result, you can't treat them like objects. This is unfortunate, because all of the nice collection classes (the Lists, Sets, Maps, etc) only work with objects.

That's where those "wrapper" classes come in. If you wrap up an "int" inside an "Integer" wrapper object, then you can treat the result as any other object. You can store it in a Collection, or do any of the many other things that only work with Objects. When you need to get the primitive back, there are methods like intValue() to get it out again.

Java 5 -- the newest version of Java -- will often do this kind of wrapping and unwrapping for you automatically. It's called "autoboxing".
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Discussion continued at https://coderanch.com/t/404102/java/java/WRAPPER-CLASSES-ADD-FUNCTIONALITY
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic