没有从Kotlin代码中找到类def

我有Kotlin代码:

cluster.removeIf { t: SolutionElement -> t.timeStart < minimumDate } //Clusters.kt:66 

集群对象是kotlin可变列表。 当我尝试在Google App Engine标准环境中运行此代码时,出现错误:

 java.lang.NoClassDefFoundError: java/util/function/Predicate at com.google.appengine.runtime.Request.process-4a2a3dcd2b375db7(Request.java) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:820) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:449) at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at java.lang.ClassLoader.loadClass(ClassLoader.java:375) at net.toolla.teamly.services.matcher.Clusters.removeExpired(Clusters.kt:66) at net.toolla.teamly.services.matcher.Clusters.pickMore(Clusters.kt:31) at net.toolla.teamly.services.matcher.BestMatchWorker.getSolutionElements(BestMatchWorker.java:232) at net.toolla.teamly.services.matcher.BestMatchWorker.match(BestMatchWorker.java:116) at net.toolla.teamly.services.matcher.MatcherService.doPost(MatcherService.java:37) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388) at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765) at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) at org.mortbay.jetty.Server.handle(Server.java:326) at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542) at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:454) at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:461) at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:297) at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:320) at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:312) at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:458) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.ClassNotFoundException: java.util.function.Predicate at com.google.appengine.runtime.Request.process-4a2a3dcd2b375db7(Request.java) 

在这个模块的build.gradle中,我有:

 compileKotlin{ kotlinOptions{ jvmTarget = 1.6 } } 

没有这个参数错误是:

 Uncaught exception from servlet java.lang.NoClassDefFoundError: net/toolla/teamly/services/matcher/Clusters$removeExpired$1 

其中“removeExpired”是包含上述行的函数的名称。

我把上面的代码改成了一些不那么方便和老的语法,但是知道如何使用一些更新的技术会很棒。

java.util.function.Predicate类是在Java 8 java.util.function.Predicate引入的,因此使用它来运行它

 ... * @since 1.8 */ @FunctionalInterface public interface Predicate<T> { 

关于这个错误:

java.lang.NoClassDefFoundError:net / toolla / teamly / services / matcher / Clusters $ removeExpired $ 1

确保你的classpath上有这个类

而不是从JDK 8的方法removeIf ,因此JDK 6不支持removeIf ,可以使用所有JDK版本支持的Kotlin标准库中的removeAll方法 。