運行Java 1.8 的JavaSE-1.8(jdk1.8.0_20)泛型函數調用Java中沒有編制8延伸的多個接口
這個類:
public class SimpleQuestion {
public static void main(String[] args) {
DoNothing();
DoNothing2();
DoNothing3();
DoNothing4();
}
public interface Interface1 {
public void go();
}
public interface Interface2<X> {
public X go2();
}
private static <X, T extends Interface2<X> & Interface1> void DoNothing() {
return;
}
private static <X, T extends Interface2 & Interface1> void DoNothing2() {
return;
}
private static <X, T extends Interface2<X>> void DoNothing3() {
return;
}
private static <T extends Interface2<T> & Interface1> void DoNothing4() {
return;
}
}
給人的編譯錯誤:
SimpleQuestion類型中的方法DoNothing()不適用於參數()
Wh那一個而不是DoNothing2,3和4?
它在Eclipse中失敗。 Oracle編譯器適用於我。我哭了錯誤! – 2014-10-03 21:06:09
但是,如果您顯式提供類型參數,它就可以工作。 – 2014-10-03 21:06:35
在Java7中爲我編譯好;可能是您正在使用的編譯器/ IDE中的一個錯誤 – Krease 2014-10-03 21:08:13