Mega Code Archive

 
Categories / Java Tutorial / Generics
 

Life without Generics

When retrieving a member from stringList1, you get an instance of java.lang.Object. In order to work with the original type of the member element, you must first downcast it to String. import java.util.ArrayList; import java.util.List; public class MainClass {   public static void main(String[] args) {     List stringList1 = new ArrayList ();     stringList1.add ("Java 5");     stringList1.add ("with generics");     String s1 = (String) stringList1.get (0);        } }