0
public class Summer {
    public static int sum(List<Integer> ints) {
        ....
    }
    public static double sum(List<Double> doubles) {
        ....
    }
}

Why does Java 6 compiles this code and Java 7 does not? Java 7 reports the error "both methods have same erasure". Is it possible to make java 7 to compile this code like java 6 does? Will I get any issues if I compile code in java 6 and run in on java 7(code cannot be compiled with java 7 javac)?

  • *Forgot to write generics List and List – user2656960 Dec 21 '15 at 16:56
  • Please intend it properly! – Mathews Mathai Dec 21 '15 at 16:59
  • @Makoto Question is different. I'm asking why does java 6 compiles this code and java 7 does not. It seems that the code is legal for java 6. I would like to know if java 7 has special flag to turn on this feature and compile code normally. – user2656960 Dec 21 '15 at 18:18
  • @user2656960 see [this one](http://stackoverflow.com/questions/12206181/generic-class-compiles-in-java-6-but-not-java-7) instead. It seems it is a bug of jdk 6 to allow it to compile. – eis Dec 21 '15 at 18:32
  • Or [this one](http://stackoverflow.com/questions/18613562/jdk-1-7-breaks-backward-compatibility-generics?rq=1), or some others. – eis Dec 21 '15 at 18:35
  • @eis thanks for the links. Second link answers to my question. – user2656960 Dec 21 '15 at 19:10

0 Answers0