Is it possible to access a Kotlin typealias from Java?

↘锁芯ラ 提交于 2019-12-23 06:59:21

问题


Suppose I have a Kotlin 1.1 typealias for a Kotlin function type like this

typealias Consumer<T> = (T) -> Unit

I can access this from Java as

import kotlin.Unit;
import kotlin.jvm.functions.Function1;

Function1<? super T, Unit> action = ...

Is it somehow possible to access the Kotlin Function1 interface from Java under its Kotlin typealias name (i.e., Consumer)?


回答1:


From the KEEP proposal for type aliases:

NB Java has no concept of "type aliases" and can't see them in class member signatures.

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.



来源:https://stackoverflow.com/questions/46552242/is-it-possible-to-access-a-kotlin-typealias-from-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!