I came to this today and spent years trying to reproduce / find out what is happening. Can someone explain why this is happening, or is it a mistake with erase / default methods like / lambda's / polymorphism? Uncommenting the default method makes it work fine, but I expected this to work, as
Conclusion:
Works fine with an object Calling consume Hello Calling accept with context Hello Calling accept via consumer... Exception in thread "main" java.lang.AbstractMethodError: Method test/LambdaTest$$Lambda$1.accept(Ljava/lang/Object;)V is abstract at test.LambdaTest$$Lambda$1/834600351.accept(Unknown Source) at test.LambdaTest.main(LambdaTest.java:24)
the code
package test; import java.util.function.Consumer; public class LambdaTest { public static void main(String[] args) { Consumer<Context> contextIgnoringObject = new ContextUnawareObject(); contextIgnoringObject.accept(new Context()); ContextIgnorer contextIgnoringLambda = () -> { System.err.println("Hello"); }; System.err.println("Calling consume"); contextIgnoringLambda.consume(); System.err.println("Calling accept with context"); contextIgnoringLambda.accept(new Context()); Consumer<Context> consumer = contextIgnoringLambda; System.err.println("Calling accept via consumer..."); consumer.accept(new Context()); } @FunctionalInterface public interface ContextIgnorer extends Consumer<Context> {
source share