Bug 69251 - [1.5] can't instantiate bounded wildcard
Summary: [1.5] can't instantiate bounded wildcard
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.1 M1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-07-03 19:31 EDT by Igor Fedorenko CLA
Modified: 2005-01-11 11:03 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Igor Fedorenko CLA 2004-07-03 19:31:05 EDT
The following code compiles by javac but not by eclipse. Not sure who's right
and who's wrong.

===================================================
package test.cheetah;
import java.util.HashMap;
import java.util.Map;
public class NewBoundedWildcard {
    private static final Map<String, Class<? extends Object>> classes 
            = new HashMap<String, Class<? extends Object>>();
}
====================================================
Comment 1 Igor Fedorenko CLA 2004-07-03 22:50:26 EDT
Forgot to mention, cheetah from CVS, sun jdk 1.5 beta2
Comment 2 Igor Fedorenko CLA 2004-07-03 23:18:49 EDT
This looks like a related problem. The following code compiles with eclipse but
not with javac. Looks like javac is correct here.

===================================================
package test.cheetah;
import java.util.HashMap;
import java.util.Map;
public class NewBoundedWildcard {
    private static final Map<String, Class<? extends Object>> classes 
            = new HashMap<String, Class>();
}
===================================================
Comment 3 Philipe Mulet CLA 2004-07-05 10:03:03 EDT
First issue is due to an extra check for wildcards in invocation, which is no 
longer necessary once bug 69141 got addressed.
Comment 4 Philipe Mulet CLA 2004-07-05 11:05:42 EDT
The second scenario feels like it should be allowed, as a raw type is always 
compatible with a parameterized type. 

So Map<String,Class> should be assignable to Map<String,Class<? extends 
Object>>.

The following testcase demonstrates this behavior:
public class X {
  class MX<E> {
    E get() { return null; }
      void foo(E e) {}
  }
  void foo() {
    MX<Class<? extends Object>> mx1 = new MX<Class<? extends Object>>();
    MX<Class> mx2 = new MX<Class>();
    mx1.foo(mx2.get()); // unsafe but legite
  }
}

Fixed first scenario, added regression test GenericTypeTest#test223