jav*_*top 8 java type-inference diamond-operator java-7
尝试在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<>() {
};
}
}
Run Code Online (Sandbox Code Playgroud)
为什么钻石语法的第二次使用不起作用?
第一次使用有什么大不同?
| 归档时间: |
|
| 查看次数: |
2240 次 |
| 最近记录: |