answersLogoWhite

0

What are object wrappers?

Updated: 8/9/2023
User Avatar

Wiki User

11y ago

Best Answer

Wrapper classes are classes that are used to make primitive variables into objects, and to make wrapped objects into primitives. int, boolean, double are all primitive data types and their respective wrapper classes are Integer, Boolean, and Double. Wrapper classes are useful in storing primitive data types in higher level data structures such as Stack<Object>, List<Object>, Queue<Object>, since primitives cannot be directly placed in these data structures they must be boxed in the wrapper classes. But, here's the good news, with the new Java 5.0, there is no need no worry about wrapper classes and boxing and unboxing (unless it's something taught in class), since there is auto-boxing and unboxing, therefore, one can directly "add" primitives to a data structure and let the JVM do the rest.

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

wrapper are the cover of the primitive type ,which converted primitive type into object.

exp...

int c;

Integer c1=new Integer c; // it wrapper the c primitive type into an object c1...

int c2= c1.intValues(); //it unwrap the c1 object into an c2 primitive type..

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are object wrappers?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What are stretch wrap machines used for?

Stretch Wrappers are usually used to wrap pallets. When the product is placed on a pallet, stretch wrappers apply film all around the pallet to create a tight package.


Delegation and Containership in C plus plus?

Delegation and "containership" relate to embedding objects as opposed to employing inheritance. Both achieve the same thing in different ways but if a class is not intended to be used with inheritance (e.g., it has no virtual destructor), then embedding an object of the class is the only option. When you embed an object you typically want to expose an interface to that object, but may not wish to expose the object's complete interface. In some cases you may wish to simplify the interface, in others you may wish to enhance it. This is achieved by declaring delegates, which are really nothing more than proxy functions that invoke the object's methods on your behalf, often simplifying the calls to those methods or enhancing them in some way. Delegates are essentially the embedded equivalent of overriding a base class virtual method. For classes that cannot be inherited, embedding is the only option. However, once embedded, your new class can then be inherited. Thus embedding is often used to provide thin wrappers to enable inheritance. You cannot inherit from the embedded object, of course, but you can inherit from the thin wrapper, provide your thin wrapper includes a virtual destructor along with one or more virtual methods. The STL containers are typical examples because they are not designed to be inherited from. Many see this as a bad thing, but it is actually a good thing. The STL is not a class hierarchy as such -- it is largely a framework of completely separate types, adaptors and algorithms that are "wired" together by iterators. It is not strictly object-oriented, but then object-oriented programming is not a magic bullet to every type of problem. The STL containers are designed to be both efficient and generic but are not intended to act as base classes. Although the STL could have provided thin wrappers for inheritance purposes, there are so many different ways to implement thin-wrappers that no single wrapper can ever cater for every programmer's needs. Thus it is left to the programmers themselves to create their own specific wrappers as and when they require them, including as much or as little generic behaviour as they need. As an example, C++ does not include a generic "matrix" data type. Many other languages do, so it seems strange that C++ does not. However, those languages that do provide a matrix data type have to cater for everyone, and this inevitably leads to unavoidable inefficiencies. But with C++, you can simply implement your own to do exactly what you want as efficiently as possible using whatever combination of containers best suits your needs, with as much or as little generics as you required. C++ is nothing if not flexible.


How can you make object from string in java?

String itself is an object dude... If you want an object out of a string then you can do this. Object obj = (Object) str; //str is the String you want to convert to object.


How do you use set and get in object-oriented programming?

A set function (or setter) is an object mutator. You use it to modify a property of an object such that the object's invariant is maintained. If the object has no invariant, a setter is not required. A get function (or getter) is an object accessor. You use it to obtain a property from an object such that the object's invariant is maintained. If the object has no invariant, you do not need a getter.


Where string is stored on Heap or Stack in java?

A String is treated as an object, meaning there is an object on the heap. Of course, the variable you define is a pointer to the object, and it is stored on the stack.A String is treated as an object, meaning there is an object on the heap. Of course, the variable you define is a pointer to the object, and it is stored on the stack.A String is treated as an object, meaning there is an object on the heap. Of course, the variable you define is a pointer to the object, and it is stored on the stack.A String is treated as an object, meaning there is an object on the heap. Of course, the variable you define is a pointer to the object, and it is stored on the stack.

Related questions

What do you get with 24 wrappers?

A pile of wrappers!A pile of wrappers!A pile of wrappers!A pile of wrappers!


Do you have habit collecting chocolate wrappers?

do you have habit of collecting chocolate wrappers


Will drymistat work with wrapper on cigar?

Leave the wrappers on. The wrappers are designed to breathe.


Can you recycle wrappers?

yes cause most wrappers are made of plastic &amp; plastic can be recycled.


Are the wrappers on chocolate bars made of paper or plastic?

The wrappers on chocolate bars made of plastic


Can you make a steel cage for men out of bread wrappers?

of course not, bread wrappers are not made of steel,


A shop sells 1 chocolaters 1 eachu can exchange 3 wrapers for 1 chocolateif you have rs 15 how many chocolates can you totally get?

You can have 22 chocolates.15 chocolates (+ their 15 wrappers)turn in the wrappers for 5 more chocolates (+ their 5 wrappers)turn in the 5 wrappers for 1 more chocolate (still have 2 leftover wrappers + 1 new wrapper)turn in the 3 wrappers for 1 more chocolate


How do you make a braid from gum wrappers?

You could get a piece of fabric and sow candy wrappers on th fabric


Is there poetry on chocolate wrappers?

no


Can you recycle jolly rancher wrappers?

No, you absolutely cannot recycle wrappers. They are a single use plastic and do not have a recycling symbol on them.


Can I design my own baby shower candy wrappers?

Yes you can. There are many places online you can go or even stores where you can have candy wrappers personalized. You can even buy a kit to print your own chocolate bar wrappers at home.


What are the default values of different primitive types?

The default values for primitive types in Java are the following:Data TypeDefault Valuebyte0short0int0long0Lfloat0.0fdouble0.0dchar'\u0000' (or 0)String (or any object)nullbooleanfalseNote if you use the Object wrappers of primitives (e.g., Byte, Integer, Double, Float, etc.) then like any Object the default value is null.