Features of Java 5.0

Source: Internet
Author: User

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");
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.