Autoboxing is a new feature offered in the Tiger (1.5) release of Java SDK. In sort auto boxing is a capability to convert or cast between object wrapper and it's primitive type.
Previously when placing a primitive data into one of the Java Collection Framework we have to wrap it to an object because the collection cannot work with primitive data. Also when calling a method that requires an instance of object than an int or long, than we have to convert it too.
But now, starting from version 1.5 we were offered a new feature in the Java Language, which automate this process, this is call the Autoboxing. When we place an int value into a collection it will be converted into an Integer object behind the scene, on the other we can read the Integer value as an int type. In most way this simplify the way we code, no need to do an explisit object casting.
Here an example how it will look like using the Autoboxing feature:
|
No comments:
Post a Comment