Reputation: 11206
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
Reputation: 11206
Filed a bug report.
Someone else filed similar bug report with same example ;)
It was fixed now (here).
Upvotes: 5