Difference between java 6 and 7 for Enum <? extends 'Interface'>

My workspace for java dev is Java6, Eclipse. The other machine runs tests with Java7. The problem is the behavior of Enum with generics, which I cannot explain to myself. In java 6, eclipse error message in editor or at compile time, but with java 7 there are no errors and applications work fine. Case: First, this is a trivial interface:

public interface TestCase {}


then i implement it in multiple enums like this

public enum TcaseFirst implements TestCase {a1,a2,} 
public enum TcaseSecond implements TestCase {a3,a4,}


In the main enum, I initialize some private EnumMap variables like this:

public enum TableC {

private static EnumMap<TableC,Enum<? extends TestCase>> box_1 = new EnumMap<TableC,Enum<? extends TestCase>> ();


When you execute the java 6 compile error message about the eclipse: "type parameter extends Enum<? extends TestCase>

not within its borders"

And in the second case, when I change the enum of TableC to:

public enum TableC {

private static EnumMap<TableC,Enum<TestCase>> box_1 = new EnumMap<TableC,Enum<TestCase>> (TableC.class);


Eclipse editor report error: Msgstr "Associated mismatch: TestCase type is not valid to replace constrained <E extends Enum<E>>

type parameter Enum<E>


In the third case, when I use java 7 and compile the same code without errors ?!

I can't figure out why this diff. I can't find anything online about this behavior, new to java 7, can I trust java 7 to compile correctly?


source to share

All Articles