FileDocCategorySizeDatePackage
BadIdea.javaAPI DocExample969Wed May 05 11:38:58 BST 2004com.oreilly.tiger.ch02

BadIdea

public class BadIdea extends Object

Fields Summary
private static List
ints
Constructors Summary
Methods Summary
public static voidfillList(java.util.List list)


       
    for (Integer i : list) {
      ints.add(i);
    }
  
public static voidmain(java.lang.String[] args)

    List<Integer> myInts = new ArrayList<Integer>();
    myInts.add(1);
    myInts.add(2);
    myInts.add(3);

    System.out.println("Filling list and printing in normal way...");
    fillList(myInts);
    printList();

    try {
      List list = (List)BadIdea.class.getDeclaredField("ints").get(null);
      list.add("Illegal Value!");      
    } catch (Exception e) {
      e.printStackTrace();
    }

    System.out.println("Printing with illegal values in list...");
    printList();
  
public static voidprintList()

    for (Integer i : ints) {
      System.out.println(i);
    }