java.is.for.desktop
java.is.for.desktop

Reputation: 11206

JDK7: Diamond inference syntax confusion

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?

Upvotes: 8

Views: 2283

Answers (1)

java.is.for.desktop
java.is.for.desktop

Reputation: 11206

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

Upvotes: 5

Related Questions