lambda - IncompatibleClassChangeError in Java -
after learning lambda expressions in java, tried practice simple examples. in first example getting following error.
exception in thread "main" java.lang.incompatibleclasschangeerror @ java.lang.invoke.methodhandlenatives.linkmethodhandleconstant(methodhandlenatives.java:384) @ com.example.lambda.hellolambda.main(hellolambda.java:15) caused by: java.lang.nosuchmethodexception: no such method: java.lang.invoke.lambdametafactory.metafactory(lookup,string,methodtype,methodhandle,methodhandle,methodtype)callsite/invokestatic @ java.lang.invoke.membername.makeaccessexception(membername.java:763) @ java.lang.invoke.membername$factory.resolveorfail(membername.java:880) @ java.lang.invoke.methodhandles$lookup.resolveorfail(methodhandles.java:1019) @ java.lang.invoke.methodhandles$lookup.linkmethodhandleconstant(methodhandles.java:1284) @ java.lang.invoke.methodhandlenatives.linkmethodhandleconstant(methodhandlenatives.java:382) ... 1 more caused by: java.lang.nosuchmethoderror: java.lang.invoke.lambdametafactory.metafactory(ljava/lang/invoke/methodhandles$lookup;ljava/lang/string;ljava/lang/invoke/methodtype;ljava/lang/invoke/methodhandle;ljava/lang/invoke/methodhandle;ljava/lang/invoke/methodtype;)ljava/lang/invoke/callsite; @ java.lang.invoke.methodhandlenatives.resolve(native method) @ java.lang.invoke.membername$factory.resolve(membername.java:852) @ java.lang.invoke.membername$factory.resolveorfail(membername.java:877) ... 4 more
the error seems error because of backward compatibility issue. don't know how fix this. many answers in stackoverflow suggested recompilation fix issue. still getting error.
my code
package com.example.lambda; public class hellolambda { static string firstname = "chansek"; static string lastname = "nayak"; interface helloservice { string hello(); } public static void main(string[] args) { helloservice helloservice = () -> {string hello="hello " + firstname + " " + lastname; return hello;}; system.out.println(helloservice.hello()); } }
the code compiles fine. running gives above mentioned error.
i using jdk1.8.0 snapshot.
is possibly because of this?
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=8019635
the way lambdas have been done in java 8 has changed, (07/2013), in not backwards compatible way.
if you've somehow managed compile compiler talks pre beta 103 lambdas, running jre of post 103 lambdas, you'll have problems.
(the hint me here metafactory name used mixed case, in java 1.8.0 beta 103 appears lower case - you're searching mixed case, not finding it.)