在Kotlin中的Jinq-如何将Lambda转换为Java SerializedLambda? [英] Jinq in Kotlin - how to convert lambda into java SerializedLambda?

查看:426
本文介绍了在Kotlin中的Jinq-如何将Lambda转换为Java SerializedLambda?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在Kotlin中拥有可序列化的lambda吗?我正在尝试使用Kotlin的Jinq库,但是它需要可序列化的lambda.有没有使之成为可能的语法?

Can I have serializable lambda in Kotlin? I am trying to use Jinq library from Kotlin, but it requires serializable lambdas. Is there any syntax that makes it possible?

更新:

我的代码:

var temp=anyDao.streamAll(Task::class.java)
   .where<Exception,Task> { t->t.taskStatus== TaskStatus.accepted }
   .collect(Collectors.toList<Task>());

我收到此错误:

Caused by: java.lang.IllegalArgumentException: 
Could not extract code from lambda. 
This error sometimes occurs because your lambda references objects that aren't Serializable.

lambda中引用的所有对象都是可序列化的(代码导致Java中没有错误).

All objects referenced in lambda are serializable (code results in no errors in java).

更新2

在调试之后,似乎Kotlin lambda并未转换为Jinq从中获取信息所需的java.lang.invoke.SerializedLambda.因此,问题在于如何将其转换为SerializedLambda.

After debugging it seems that kotlin lambda isn't translated into java.lang.invoke.SerializedLambda which is required by Jinq to get information from. So the problem is how to convert it to SerializedLambda.

推荐答案

我是Jinq的制造商.我还没有时间查看Kotlin支持,但是根据您的描述,我假设Kotlin将其lambda编译为实际的类或其他内容.因此,Jinq可能需要一些特殊的代码来破解开放的Kotlin lambda,并且还可能需要特殊的代码来处理生成的代码中的任何异常Kotlin-ism. Jinq应该能够处理它,因为先前已对其进行了改进以处理Scala lambda.

I'm the maker of Jinq. I haven't had the time to look at Kotlin-support, but based on your description, I'm assuming that Kotlin compiles its lambdas into actual classes or something else. As such, Jinq would probably need some special code for cracking open Kotlin lambdas, and it may also need special code for handling any unusual Kotlin-isms in the generated code. Jinq should be capable of handling it because it was previously retrofitted to handle Scala lambdas.

如果您在Jinq github上提出有关此问题的信息,以及一个小的Kotlin示例(以源文件和.class文件的形式),那么我可以快速浏览一下可能涉及的内容.如果很小,我可以进行更改.不幸的是,如果看起来需要做很多工作,我认为我真的没有理由为在Jinq中添加Kotlin支持投入大量资源.

If you file an issue in the Jinq github about it, along with a small Kotlin example (in both source and .class file form), then I can take a quick peek at what might be involved. If it's small, I can make those changes. Unfortunately, if it looks like a lot of work, I don't think I can really justify putting a lot of resources into adding Kotlin support to Jinq.

这篇关于在Kotlin中的Jinq-如何将Lambda转换为Java SerializedLambda?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆