dennis lucero created NETBEANS-3802:
---------------------------------------

             Summary: Hint suggests invalid replacement with lambda for 
implementations of interfaces with only default methods
                 Key: NETBEANS-3802
                 URL: https://issues.apache.org/jira/browse/NETBEANS-3802
             Project: NetBeans
          Issue Type: Bug
          Components: java - Hints
    Affects Versions: 11.2
         Environment: JDK 13
            Reporter: dennis lucero


{code:java}
    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");
            }
        };
    }
{code}
For this code NetBeans has a hint stating
{quote}This anonymous inner class creation can be turned into a lambda 
expression.
{quote}
in the line with {{new Dog()}}. Replacing the code using the hint results in
{code:java}
final Dog dog = () -> {
    System.out.println("Woof");
};
{code}
which is invalid code
{quote}incompatible types: Dog is not a functional interface
no abstract method found in interface Dog
{quote}

(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.)



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org
For additional commands, e-mail: commits-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to