JDK7:钻石推理语法混乱

时间:2010-11-02 06:26:06

标签: java type-inference java-7 diamond-operator

尝试在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<>() {
    };
  }
}

为什么钻石语法的第二种用法不起作用?

第一次使用有什么大不同?

1 个答案:

答案 0 :(得分:5)

提交 bug report 其他人使用相同的例子提交了 similar bug report ;)
它现在已修复( here )。