Listing 1

1 package example1;
2
3 import java.util.ArrayList; 4
5 public class OldCollection{ 6
7 public
8 static void main(String[] a){
9 ArrayList strLst =
10 new ArrayList();
11 strLst.add("hello");
12 strLst.add("goodbye");
13 //...
14 //Object reference
15 String strFromList =
16 (String)strLst.get(1);
17 }
18 }

Listing 2

1 package example1;
2
3 import java.util.ArrayList;
4
5 public class UseGenerics{
6
7 public
8 static void main(String[] a){
9 ArrayList strLst =
10 new ArrayList();
11 strLst.add("hello");
12 strLst.add("goodbye");
13 //...
14 String strFromList =
15 strLst.get(1);
16 }
17 }

Listing 3

1 class GenericBean{
23
private VarType x;
45
public GenericBean(){}
6 public GenericBean(VarType x){
7 this.x = x;
8 }
9
10 public VarType getX(){
11 return x;
12 }
13 public void setX(VarType x){
14 this.x = x;
15 }
16 }