Generic class compiles in Java 6, but not Java 7

前端 未结 2 1752
北恋
北恋 2020-12-09 10:22

I have an interface in Java 6 that compiles correctly:

public interface IMultiMap extends Map> {

    public int valueSize(         


        
2条回答
  •  独厮守ぢ
    2020-12-09 10:47

    I think it's a bug in 1.6 that was fixed in 1.7. Extract from this page:

    Synopsis: A Class Cannot Define Two Methods with the Same Erased Signature but Two Different Return Types
    Description: A class cannot define two methods with the same erased signature, regardless of whether the return types are the same or not. This follows from the JLS, Java SE 7 Edition, section 8.4.8.3. The JDK 6 compiler allows methods with the same erased signature but different return types; this behavior is incorrect and has been fixed in JDK 7.
    Example:

    class A {
       int m(List ls) { return 0; }
       long m(List ls) { return 1; }
    }
    

    This code compiles under JDK 5.0 and JDK 6, and is rejected under JDK 7.

提交回复
热议问题