尝试在JDK7中编译如下代码:
import java.nio.file.*;
public final class _DiamondSyntaxErrors {
public interface InterfaceA<T> {
}
public abstract static class ClassA<T>
implements InterfaceA<T> {
protected ClassA() {
}
}
public static void main(String... args) {
// no error
InterfaceA<Path> classA = new ClassA<>() {
};
// error: cannot infer type arguments for SimpleFileVisitor<>
FileVisitor<Path> visitor = new SimpleFileVisitor<>() {
};
}
}
为什么菱形语法的第二种用法不起作用?
与第一次使用的最大区别是什么?
最佳答案
提交了一个 bug report .
其他人提交 similar bug report 同样的例子 ;)
现在已修复 ( here )。
关于java - JDK7 : Diamond inference syntax confusion,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4075394/