0

I recently found that the following interface:

   public static interface LoggImpl{
        public default void Log(String s){

        }
    }

Cannot be referenced as a lambda:

// compile error: "no target method found"
static LoggImpl impl = (String s)-> {
    System.out.println(s);
};

Does this mean that we can't define default functionality for a single function lambda?

jayunit100
  • 17,388
  • 22
  • 92
  • 167

1 Answers1

1

You CAN define default methods for a SAM interface, but you MUST define one and only one abstract method other than methods from the Object class: functional interfaces

So you define a SAM with one abstract method (no default, not found in Object class signature), then as many default methods (with different signatures) as you want.

rdlopes
  • 661
  • 4
  • 11