Bug 114997

Summary: [1.5][compiler] type mismatch with Collections.emptyList and wildcard
Product: [Eclipse Project] JDT Reporter: Andrew Bachmann <AndrewBachmann>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED DUPLICATE QA Contact:
Severity: normal    
Priority: P3    
Version: 3.2   
Target Milestone: 3.1.2   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Andrew Bachmann CLA 2005-11-03 16:57:28 EST
The following code generates an error in eclipse 3.1.1 and 3.1m2, but it
compiles fine in both eclipse 3.1 and javac version 1.5.0_05.  It doesn't matter
if the "Interface" class below is defined as a class or as an interface, it
generates the error in both cases.  The error is:
 "Type mismatch: cannot convert from List<Object> to List<? extends Test.Interface>"

import java.util.Collections;
import java.util.List;

public class Test {
  public interface Interface {
	  // nothing
  }
  public List<? extends Interface> field = Collections.emptyList();
}
Comment 1 Andrew Bachmann CLA 2005-11-03 17:02:59 EST
A workaround that doesn't involve suppressing warnings is to explicitly supply
the extended type:

  public List<? extends Interface> field = Collections.<Interface>emptyList();
Comment 2 Philipe Mulet CLA 2005-11-03 18:02:38 EST
A patch for 3.1.1 is available, see some comment in bug 112268.
Added regression test: GenericTypeTest#test866

*** This bug has been marked as a duplicate of 112268 ***
Comment 3 Olivier Thomann CLA 2006-01-10 09:59:43 EST
Verified in M20060109-0800 for 3.1.2