Menu

#46 Unmodifiable Collections

open
5
2009-08-20
2009-08-20
No

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)

Discussion


Log in to post a comment.