是否可以从 Java 访问 Kotlin 类型别名?
Is it possible to access a Kotlin typealias from Java?
假设我有一个 Kotlin 1.1 typealias
像这样的 Kotlin 函数类型
typealias Consumer<T> = (T) -> Unit
我可以从 Java 作为
访问它
import kotlin.Unit;
import kotlin.jvm.functions.Function1;
Function1<? super T, Unit> action = ...
是否可以通过 Kotlin 类型别名(即 Consumer
)从 Java 访问 Kotlin Function1
接口?
来自 KEEP proposal 类型别名:
NB Java has no concept of "type aliases" and can't see them in class member signatures.
所以不,您不能使用 Java 中的类型别名,您只会看到在 Kotlin 中具有类型别名的任何参数或变量的实际类型。
假设我有一个 Kotlin 1.1 typealias
像这样的 Kotlin 函数类型
typealias Consumer<T> = (T) -> Unit
我可以从 Java 作为
访问它import kotlin.Unit;
import kotlin.jvm.functions.Function1;
Function1<? super T, Unit> action = ...
是否可以通过 Kotlin 类型别名(即 Consumer
)从 Java 访问 Kotlin Function1
接口?
来自 KEEP proposal 类型别名:
NB Java has no concept of "type aliases" and can't see them in class member signatures.
所以不,您不能使用 Java 中的类型别名,您只会看到在 Kotlin 中具有类型别名的任何参数或变量的实际类型。