是否可以从Java访问Kotlin类型别名? [英] Is it possible to access a Kotlin typealias from Java?
本文介绍了是否可以从Java访问Kotlin类型别名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个Kotlin 1.1 typealias
,用于像这样的Kotlin函数类型
Suppose I have a Kotlin 1.1 typealias
for a Kotlin function type like this
typealias Consumer<T> = (T) -> Unit
我可以通过Java来访问它
I can access this from Java as
import kotlin.Unit;
import kotlin.jvm.functions.Function1;
Function1<? super T, Unit> action = ...
是否可以通过Java以Kotlin类型别名(即Consumer
)访问Kotlin Function1
接口?
Is it somehow possible to access the Kotlin Function1
interface from Java under its Kotlin typealias name (i.e., Consumer
)?
推荐答案
来自 KEEP建议用于类型别名:
NB Java没有类型别名"的概念,并且在类成员签名中看不到它们.
NB Java has no concept of "type aliases" and can't see them in class member signatures.
因此,不能,您不能使用Java中的类型别名,您只会在Kotlin中看到具有类型别名类型的任何参数或变量的实际类型.
So no, you can't use typealiases from Java, you'll just see the actual types of any parameter or variable that has a typealias'd type in Kotlin.
这篇关于是否可以从Java访问Kotlin类型别名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文