-
Junior Member
Wrapper class
What is mean by Wrapper class?
What is it use...?
-
Junior Member
Re: Wrapper class
Hi,
The built-in object type for the java primitive type is called as the wrapper class.
It will be used when the primitive type is needed as a object type for some purpose.
eg:
int count=9;
if the count variable is needed as an object type then u can use the built in object type for int ie. Integer
Integer count = new Integer(9);
Hope this is useful.
Regards,
Elango
-
Contributing Member
Re: Wrapper class
For all the primitive data types we have their corresponding objects - Eg: for int we have Integer and so on. These are known as wrapper classes.
Prior to Java 5, there were methods that accepted only objects as their arguments, I think these wrapper classes would be used there.
The only other use I have found is in the reflection API, which relies completely on objects. I dunno if there is any other place where they can be used and not the primitives.
Regards,
Sahil
--Smile, It makes people wonder what you are thinking!!!
-
Junior Member
Re: Wrapper class
Hi,
First of all you should know that Java's primitive datatypes are not Objects.
But in actual practice there will be situations where you will have to pass this primitive values to some functions that accepts only Objects. So there should be some mechanism to represent the primitive values as Objects.
Here comes the need of wrapper classes. These are builtin classes provided by java, to allow you to represent a premitives as objects. Java provides wrapper classes for all primitive datatypes.
int ----> Integer
char ----> Character
float ----> Float
double ---->Double, etc.
eg
int a = 10
Integer i = new Integer(a);
now you can pass this to any functions accepting objects. And also you can use many builtin fuctions provided by java.
Wrapper classes provide so many good and useful functions like parseXxx(),
xxxValue() etc. where xxx stands for corresponding primitive datatypes. These functions will help you to convert from String to primitive and from object to primitive.
ptmidhun@gmail.com
But, Now these things are more easy, From J2SE5.0 onwards java also supports autoboxing and autounboxing. A feature copied from C#.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules