Hi Ojong Tabot,
Java 1.5 introduced the autoboxing of primitive and wrapper classes. Autoboxing means you can do things like:
Boolean myBoolean = true;
char myChar = new Character('c');
Before java 1.5 you needed to do like this:
Boolean myBoolean = new Boolean(true); // or new Boolean("true");
char myChar = new Character('c').charValue();
Here is a relation of primitive types and yours wrapper classes:
byte --> Byte
short --> Short
int --> Integer
long --> Long
float --> Float
double --> Double
char --> Character
boolean --> Boolean
only the wrapper class
Character has one constructor that has a char as parameter. All other have two constructors, one of your primitive type and other using a
String.
Let's see what you have posted:
Originally posted by Ojong Tabot:
a. Integer i1 = new Integer(10);
b. Integer i2 = 10;
c. Int i3 = new Integer(10);
d. int i4 = 10;
a. Here is ok. It's used a constructor that has your primitive type as parameter.
b. It's ok. Here we see a boxing case, what happens here is:
Integer i2 = new Integer(10);
But remember, is done in a automatic way. (only after 1.5)
c. Wrong. There isnt a
Int type.
d. Ok too, normal use of a int.
if you still continue with your doubt, feel free to ask again and i'll try to make it more clear.
Your's,
Raphael Rabadan
[ July 05, 2008: Message edited by: Raphael Rabadan ]