Bug 69251

Summary: [1.5] can't instantiate bounded wildcard
Product: [Eclipse Project] JDT Reporter: Igor Fedorenko <igor>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 3.0   
Target Milestone: 3.1 M1   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

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