problem in wrapper class
Plz assist me to clear some doubt in wrapper class.
Actually wrapper class is used to convert primitive data types to object type.
Integer a=new Integer(10);
Now 'a' would be Integer object.
As far as my knowledge, object cannot go through any arithmetic operation directly .But when i gone through these steps in eclipse ide a++ worked perfectly.How it would be possible.Hope some one will clariffy this doubts,
All comments regarding this tipic is highly appreciated.
There is only one class that can undergo arithmetic operation, and that is the String class. It can only add two Strings together, which is called concatenation , when you add them together. The Inter class just allows for certain operations that PRIMITIVES cannot do:
Integer a, b;
assuming they have been assigned values:
a + b will NOT work
On the other hand
int a, b;
a + b WILL work because int is a primitive
I suggest that you use the Integer, Double, Float, and so on classes, only when you need some of the methods they provide.
First let me know which version of Java you are using. Because in jdk1.4 you can;t do arithmetic operation over Integer objects. But from Java 5, because of the concepts of boxing and unboxing, Integer,Double Objects can also do arithemetic operations, as the JVM internally
1. converts the objects to primitive values
2. Does the arithmetic operation
3. Converts the result to an Object datatype.
Eh, i was completely wrong in my previous post... i guess there are downsides to switching over the 5 very late :\.
Anyways, sorry for a misleading post, dont listen to me :)
I don't think there are any downsides in switching to 5.0. By switching you can also use new feature that are been introduced in Java 5.0