Unmodifiable Collections
Brought to you by:
zhourenjian
bug when using read-only collections. the following code will throw an error.
List l1 = new ArrayList(); l1.add("A"); l1.add("B");
List l2 = Collections.unmodifiableList(l1);
try {
l2.size();
}
catch (Exception e) { System.out.println("it is OK");}
System.out.println("end test");
It seems that the problem is with inner classes, like java.util.Collections.UnmodifiableRandomAccessList <T>, not inherithing parent methods like size(), etc)