Saturday, August 14, 2010


Courtesy of

When we compile this code, we get a warning

Note: uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

To fix this, use generics; note how <String> is added to List declaration

Code compiles without warning; however we get runtime error:

Exception in thread "main" java.lang.UnsupportedOperationException
    at java.util.AbstractList.add(
    at java.util.AbstractList.add(
    at ToDo.main(

The asList() method creates a fixed-size list that is backed by the array, so no additions are possible.

No comments:

Post a Comment