Question

Try to compile the following code in 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<>() {
    };
  }
}

Why doesn't the second usage of the diamond syntax work?

What's the big difference to the first usage?

Was it helpful?

Solution

Filed a bug report.
Someone else filed similar bug report with same example ;)
It was fixed now (here).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top