I was playing around with Java 8 lambdas, method references and interface default methods to explore the wonderful world of currying, and then I got this Java error I cannot understand.
Here is the code :
public class Main {
public interface CurryBiConsumer<T, U> extends BiConsumer<T, U> {
default public CurryConsumer<U> curryFirst(T t) {
return (u) -> accept(t, u);
}
default public CurryConsumer<T> currySecond(U u) {
return (t) -> accept(t, u);
}
}
public interface CurryConsumer<T> extends Consumer<T> {
default public Runnable curry(T t) {
return () -> accept(t);
}
}
static void execute(Runnable r) {
System.out.println("BEFORE");
r.run();
System.out.println("AFTER");
}
static void display(String str, int count) {
System.out.println("DISP: " + str + " " + count);
}
public static void main(String[] args) {
CurryBiConsumer<String, Integer> bc = Main::display;
execute(bc.curryFirst("Salomon").curry(42));
}
}
Eclipse gives me no error but when I run it, I get this runtime error :
Exception in thread "main" java.lang.BootstrapMethodError: call site initialization exception
at java.lang.invoke.CallSite.makeSite(CallSite.java:328)
at java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:296)
at com.test8.Main.main(Main.java:34)
Caused by: java.lang.ClassFormatError: Duplicate method name&signature in class file com/test8/Main$$Lambda$1
at sun.misc.Unsafe.defineAnonymousClass(Native Method)
at java.lang.invoke.InnerClassLambdaMetafactory.spinInnerClass(InnerClassLambdaMetafactory.java:324)
at java.lang.invoke.InnerClassLambdaMetafactory.buildCallSite(InnerClassLambdaMetafactory.java:194)
at java.lang.invoke.LambdaMetafactory.altMetafactory(LambdaMetafactory.java:473)
at java.lang.invoke.CallSite.makeSite(CallSite.java:301)
... 2 more
Can someone explain What is this error, why it is happening and how to get around it ?
Thanks :)
CurryBiConsumer
needs to be a functional interface – Chemicaljava -jar
instead of through eclipse? – DelrosarioCurryBiConsumer<String, Integer> bc = Main::display;
– Madelenemadelin