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
)?
One extremely useful feature in IntelliJ IDEA and Android Studio is the ability to see the compiled bytecode of your Kotlin code and then the decompiled Java code. For this, press Ctrl+Shift+A (Cmd+Shift+A on Mac) to invoke the action search, then type “Show Kotlin Bytecode” (or “skb”) and press Enter.
If your question is can you use kotlin files in java files and vice versa then the answer is yes.
Whenever two-byte code files run on JVM, due to their equivalent nature they can communicate with each other and that's how interoperability is established in kotlin for Java. And makes Kotlin 100% interoperable with Java.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With