4 Replies Latest reply: Sep 23, 2010 12:40 AM by EJP RSS

    Problem with adding a new element to the list

    843793
      import java.util.Arrays;
      import java.util.List;

      public class Test {

      public static void main(String[] args)
      {
      List<Object> objs = Arrays.<Object>asList(1,"two");
      List<? super Integer> ints = objs;
      ints.add(3);
      }
      }

      ints has been declared with type super. So I should be able to add elements to the list ints. But I'm getting the following runtime exception

      Exception in thread "main" java.lang.UnsupportedOperationException
      at java.util.AbstractList.add(Unknown Source)
      at java.util.AbstractList.add(Unknown Source)
      at p1.Test.main(Test.java:12)