Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 944
java.is.for.desktop Avatar asked Nov 02 '10 06:11

java.is.for.desktop


1 Answers

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

like image 77
java.is.for.desktop Avatar answered Nov 07 '22 03:11

java.is.for.desktop