Bug 71099 - [1.5] can put an Object into an ArrayList<? super Integer>
Summary: [1.5] can put an Object into an ArrayList<? super Integer>
Status: RESOLVED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M1   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-07-29 13:11 EDT by Markus Keller CLA
Modified: 2004-08-10 12:39 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2004-07-29 13:11:30 EDT
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());
}
Comment 1 Kent Johnson CLA 2004-08-10 12:39:46 EDT
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)