Community
Participate
Working Groups
I200407271028: These methods compile without warning, but fail with a CCE at run-time. When I inline doBug1(), I get a compile error for al.add(n) (correct). I think I shouldn't be allowed to put anything which is not at least an Integer into an ArrayList<? super Integer>. static void bug1() { ArrayList<Integer> al= new ArrayList<Integer>(); doBug1(al); Integer i= al.get(0); //java.lang.ClassCastException: java.lang.Double System.out.println(i); } static void doBug1(ArrayList<? super Integer> al) { Object n= new Double(12.4); al.add(n); // al.add(new Double(12.3)); // compile error (OK) System.out.println(al.toString()); }
Using the latest, I get the following error: The method add(? super Integer) in the type ArrayList<? super Integer> is not applicable for the arguments (Double)