Automatic boxing/unboxing (auto-boxing/unboxing)
No automatic boxing/unboxing:
int int1 = 1;
Integer integer2 = new Integer(int1);
int int3 = integer2.intValue();
Automatic Boxing/unpacking:
int int1 = 1;
Integer integer2 = int1; // 自動裝箱
int int3 = integer2; // 自動拆箱
Generics (Generic Types)
Generics are like templates for C + +. The original collection API plus generics support, the increase in the type of inspection, reduce the chance of programming errors.
No generics:
HashMap hm = new HashMap();
int i=1;
String tt="test";
hm.put(new Integer(i), tt);
Use generic:
HashMap <Integer, String>hm = new HashMap<Integer, String> ();
int i=1;
String tt = "test";
hm.put(i, tt); // 在這裏對int自動裝箱成Integer,也使用了參數的型別檢查
The new feature of automatic boxing is probably learned from the C # language, and Java has become more and more like C #. However, Java for automatic boxing/unboxing support, only the use of compiler implementation, in the Java bytecode, there is no automatic boxing/unboxing of the opcode (opcode).
Note (Annotation)
The Annotation full name is Program Annotation facility, a new feature of the Java SE 5.0. Java's Annotation is similar to. NET's attributes. Java annotations are an interface (interface) that inherits from Java.lang.annotation.Annotation. Class File is labeled with the acc_annotation tag.
// JDK 1.4
/**
* @todo to be implemented
**/
void gimmeSomeLoving() {
throw new Exception("not implemented");
}
// JDK 1.5
@todo void gimmeSomeLoving() {
throw new Exception("not implemented");
}