Thursday, July 07, 2005

ONJava.com: Generics in J2SE 5.0

ONJava.com: Generics in J2SE 5.0: "Generics in J2SE 5.0
by Budi Kurniawan
07/06/2005

Generics are the most important feature in J2SE 5.0. They enable you to write a type (a class or an interface) and create an instance of it by passing a reference type or reference types. The instance will then be restricted to only working with the type(s). For instance, the java.util.List interface in Java 5 has been made generic. When creating a List object, you pass a Java type to it and produce a List instance that can only work with objects of that type. That is, if you pass String, the List instance can only hold String objects; if you pass Integer, the instance can only store Integer objects. In addition to parameterized types, you can create parameterized methods, too."

No comments: