//: c08:GopherList.java // From Thinking in Java, 2nd Edition // Available at http://www.BruceEckel.com // (c) Bruce Eckel 1999 // Copyright notice in Copyright.txt // A type-conscious ArrayList import java.util.*; class Gopher { private int gopherNumber; Gopher(int i) { gopherNumber = i; } void print(String msg) { if(msg != null) System.out.println(msg); System.out.println( "Gopher number " + gopherNumber); } } class GopherTrap { static void caughtYa(Gopher g) { g.print("Caught one!"); } } class GopherList { private ArrayList v = new ArrayList(); public void add(Gopher m) { v.add(m); } public Gopher get(int index) { return (Gopher)v.get(index); } public int size() { return v.size(); } public static void main(String[] args) { GopherList gophers = new GopherList(); for(int i = 0; i < 3; i++) gophers.add(new Gopher(i)); for(int i = 0; i < gophers.size(); i++) GopherTrap.caughtYa(gophers.get(i)); } } ///:~