1000 Java Tips ebook
Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java
programming articles and tips. Please take your copy here.
Take your copy of free "Java Technology Screensaver"!.
JavaFAQ Home » General Java
Autoboxing, introduced in Java 5, is the automatic conversion that Java makes between the
primitive (basic) types and their corresponding object wrapper classes
This sugar coating the avoids the tedious and hard-to-read casting
typically required by Java Collections, which can not be used with primitive types.
|With Autoboxing||Without Autoboxing|
i = 1;
j = 2;
i = j;
j = i;
i = 1;
j = new Integer(2);
i = j.valueOf();
j = new Integer(i);
Prefer primitive types
Use the primitive types where there is no need for objects
for two reasons.
- Primitive types will not be slower than their corresponding wrapper
types, and may be a lot faster.
- There can be some unexepected behavior involving
== (compare references)
.equals() (compare values). See the reference below for
Printer Friendly Page
Send to a Friend
Search here again if you need more info!