//ProblemBeforeGenerics.java

import java.util.ArrayList;
import java.util.List;
import java.util.Date;

public class ProblemBeforeGenerics
{
    public static void main(String[] args)
    {
        List myList = new ArrayList();
        myList.add(new Date());
        myList.add(new String("Hello, world!"));
        myList.add(Integer.valueOf(6));
        System.out.println((Date)myList.get(0));
        System.out.println((String)myList.get(1));
        System.out.println((Integer)myList.get(2));

        //The following code snippet illustrates the problem
        //that Java had before generics ... you could add an
        //object of any kind to a container, so you had to know
        //what was stored where and make the appropriate cast
        //when retrieving an object from the container. This
        //code snippet compiles without any problem, but causes
        //a runtime exception because of the incorrect cast.
        //It is much better to catch such problems at compile time!

        //myList.add(new String("So long!"));
        //System.out.println((Integer)myList.get(3));
    }
}
/*  Output:
    Thu Jul 26 16:31:25 ADT 2018
    Hello, world!
    6
*/
