This page describe the major new features added in Java 5.
@Override which marks a method that
overrides a superclass method
int i = 19; Integer iObj = i; int j = iObj; // i and j are equal
List<Integer> list = new ArrayList<Integer>(); // see "Generics" int i = 19; list.add(i); int j = list.get(0); // i and j are equal
Car[] cars = new Car[](5);
// populate array of Car objects
for (Car car : cars) {
// Use the variable car inside the loop.
}
List<Car> cars = new ArrayList<Car>() // see "Generics"
// populate List of Car objects
for (Car car : cars) {
// Use the variable car inside the loop.
}
enum Season { WINTER, SPRING, SUMMER, FALL }
Season season = SPRING;
for (Season season : Season.values()) {
// use season variable
}
ordinal method on it
List<String> myList = new ArrayList<String>(); // only String objects can be added to myList.
List<Dog>
can be passed to a method that accepts
List<? extends Animal>
or even
List<? extends Object>)
import static org.junit.Assert.*; // can now use static assert methods from the Assert class // without prefixing them with "Assert."
public void washCars(Car... cars) {
for (int i = 0; i < cars.length; i++) {
Car car = cars[i];
// wash the car
}
}
// call like this
washCars(car1, car2, car3);
Copyright © 2007 Object Computing, Inc. All rights reserved.