I have been exploring and trying to explore and understand the new features in Java 1.5. I know, it is actually old news and I have been using them. But the other day I realized I really hadn't explored all of them and in the case of Annotations just kinda ignored the fact they were there. I will hopefully get to the new features of release 6 sooner.
Auto Boxing and Unboxing

We have all wrote code like this below to convert between primitive types like ints and objects.

Integer myInt = new Integer (27);
and
int i = myInt.parseInt();

Well 1.5 allows automatic conversion between primitive and object types.
So now you can write cleaner and less code that looks like this. This is
called autoboxing and unboxing.

Integer myInt = 27;

and

int i = myInt;

The code is really is more elegant than casting code everywhere.
The precise rules for autoboxing can be found in this

JCP article.
 


		
Advertisements