简体   繁体   English

Java 相当于 Kotlin 的 Function0 和 Function1 是什么?

[英]What is Java equivalent to Function0 and Function1 of Kotlin?

I was trying to implement Github Link library in my java project.我试图在我的 java 项目中实现Github 链接库。 And I don't want to use Kotlin in my project, so I was custom coding the whole library into Java.而且我不想在我的项目中使用 Kotlin,所以我将整个库自定义编码为 Java。 Any help appreciated.任何帮助表示赞赏。 It's hard to convert Kotlin to Java rather the opposite.很难将 Kotlin 转换为 Java 而相反。 I have worked with decompiling Kotlin Bytecode, which somewhat helps you to convert it into Java.我曾反编译 Kotlin 字节码,这在一定程度上有助于您将其转换为 Java。 And that's where it's getting confusing where Function0 and Function1 comes into picture.这就是 Function0 和 Function1 出现的地方变得令人困惑的地方。 I also saw this Question on Stackoverflow .我还在Stackoverflow 上看到了这个问题 But I can't use Kotlin in my project.但我不能在我的项目中使用 Kotlin。

The equivalent are the Functional Interfaces Supplier and Function , respectively等效的分别是功能接口SupplierFunction

They have the same signatures, and are SAM (Single abstract methods), so they are replaceable by an in-line lambda.它们具有相同的签名,并且是 SAM(单一抽象方法),因此它们可以被内嵌的 lambda 替换。

https://www.baeldung.com/java-8-functional-interfaces#Suppliershttps://www.baeldung.com/java-8-functional-interfaces#Functions https://www.baeldung.com/java-8-functional-interfaces#Suppliershttps://www.baeldung.com/java-8-functional-interfaces#Functions

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM