4 ms·
Kotlin should be close-to-identical* in terms of bytecode it immits for straightforward code like this, it's designed to very closely match Java capabilities, a
by dtech 5y ago
Kotlin should be close-to-identical* in terms of bytecode it immits for straightforward code like this, it's designed to very closely match Java capabilities, among others to make sure interop is very good.
* Exception is supporting things like default methods on JVM 1.6 bytecode
- pjmlp 5y agoApparently that isn't the case. Additionally it is stuck on Java 8 view of the world, otherwise those .class files won't be usable on Android toolchain thanks Google.
- jontro 5y agoLooks like it supports generating class files up to java 16 https://kotlinlang.org/docs/compiler-reference.html#jvm-target-version https://kotlinlang.org/docs/compiler-reference.html#jvm-targ...
- pjmlp 5y agoYeah, but it can't make use of JVM bytecodes without DEX counterparts, nor JVM abilities unknown to ART.
- dtech 5y agoIncorrect, the Kotlin compiler allows you to specify the target JVM level, it can generate JVM 1.6 bytecode (for android) up to 16. I know for a fact it uses different bytecode features if the level is >= 1.8, not sure how smart it is above that.
- pjmlp 5y agoIt can only generate bytecode features that ART understands, and D8 is able to convert into DEX, thus is the price of Android marriage. Going forward while for Java code there is no worry about using SIMD, JNI replacement, value types, Kotlin code will need to make use of KMM for code that is supposed to target both JVM and Android.
- dtech 5y agoAre you so dense that you cannot understand that the Kotlin compiler can do gasp different things depending on different settings? It can do stuff android doesn't support if you set the bytecode target level to > 1.8 It's like using modern Javascript features but providing a polyfill for older browsers.
- pjmlp 5y agoWhich produces libraries that are worthless to be consumed from Android without recompiling. Also stuff like value classes will have different semantics in memory consumption and performance across targets. Maybe some learning required?
- dtech 5y agoThose are bytecode level related. You can't consume Java 16 libraries on Android either. It's not related to Kotlin at all. You are either being deliberately obtuse or you genuinely have difficulty to understand that Java version, bytecode version, Kotlin compiler output and what bytecode Android supports are totally independent concepts.
- pjmlp 5y agoEnjoy #KotlinFirst, I am out of this thread. It is going to be fun to port back stuff to Java.