2010年7月21日 星期三

java 1.4 和 1.5 的差別

Java 1.5 has many new features, compare to Java 1.4. See the link for a complete explanation. Some of the features are:

  • Generics (e.g. typed collections, like Set)
  • Enhanced for loop (for (String s : set) {...})
  • Autoboxing/unboxing (automatically convert between types like Integer to int and vice versa)
    Before Java 5

    int intPrimitive = intObject.intValue();
    intPrimitive++;
    intObject = new Integer(intPrimitive);

    Using Java 5

    Integer intObject = new Integer(10);
    intObject++;

  • Typesafe enums (enum is now a keyword, types can be created out of enums)
  • Varargs (for printf() function, allows variable number of arguments)
  • Static import (can now import static methods of a class, such as java.lang.Math)
  • Annotations

沒有留言:

張貼留言