Details
-
Bug
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
11.2, 12.5
-
None
-
JDK 13
Description
interface Dog { default void run() { } default void bark() { } } public static void foo() { final Dog dog = new Dog() { @Override public void bark() { System.out.println("Woof"); } }; }
For this code NetBeans has a hint stating
This anonymous inner class creation can be turned into a lambda expression.
in the line with new Dog(). Replacing the code using the hint results in
final Dog dog = () -> { System.out.println("Woof"); };
which is invalid code
incompatible types: Dog is not a functional interface
no abstract method found in interface Dog
(Real world example: http://jdbi.org/apidocs/org/jdbi/v3/core/statement/SqlLogger.html This style of interfaces would also be a nice alternative to Swing’s *Listener/*Adapter pairs.)