Slightly bizarre question, but has anyone written ...
# general-advice
r
Slightly bizarre question, but has anyone written a transpiler from Kotlin to Java? My thinking is that for a lot of JVM libraries it's nice not to have an extra stdlib on the classpath, locking you into a Kotlin version, extra bytes to download, risking the ire of Java devs who hate that particular other JVM language for whatever reason... But it would be nice to write them in Kotlin 🙂. So what if there were a transpiler that would turn your Kotlin into really nice idiomatic Java as a build step?
e
why transpile? your JVM consumers are probably consuming bytecode right?
if you just want to remove the kotlin-stdlib dependency, you can do that, https://kotlinlang.org/docs/gradle-configure-project.html#dependency-on-the-standard-library
you will need to do some extra work to replace Kotlin intrinsics in bytecode with JVM equivalents, and either avoid using anything non-inline that can't be easily replaced or use a tool to repackage those parts of stdlib into your output, but it is doable
r
Perhaps that would be better... I suppose I was thinking it would be nice to have someone else turn my
listOf("something)".map { it.length }
into
List.of("something").stream().map(it -> it.length()).toList();
and that sort of thing. And it might be easier to fix any weirdnesses as actual Java (even if it didn't compile) than to work out what Kotlin would work. I was sort of imagining doing the initial write in Kotlin, committing the result as Java and treating it as a Java lib thereafter.
e
the semantics of that are different though