ENTERPRISE APPLICATION
DEVELOPMENT-1
Tharanga Ekanayake
BSc (Special) MIS, First Class
Generics in Java
• Generics in java were introduced as one of features in JDK 5
• The angular brackets “<>” used in generics
Java Generics Example
*The List interface represents a list of Object instances. This means that we could put
any object into a List. Here is an example:
List list = new ArrayList();
list.add(new Integer(2));
list.add("a String");
*Because any object could be added, you would also have to cast any objects
obtained from these objects. For instance:
Integer integer = (Integer) list.get(0);
String string = (String) list.get(1);