Wouldn’t it be cool if you could take a mixed Java+Kotlin codebase and transpile it to JavaScript?
Perhaps one option is interoperability with Google’s GWT successor, J2CL (in the process of being open-sourced now, AFAIK).
J2CL, in a nutshell (more info here: https://www.youtube.com/watch?v=P4VhPck5s_g after 36th minute)
- Fast incremental transpilation: one Java file to one readable ES6 JS file
- No optimizations. Minifying, dead-code elimination, even transpiling to ES5/ES3 are all expected to be done by standard JS tools like Google Closure and perhaps Webpack in future
- Some small tricks like name mangling for overloaded methods and Java “this” semantics still in place
- Minimal Java JRE (shared with GWT and j2objc) for supporting Java collections and utility classes - also transpiled to JS
- jsinterop (https://docs.google.com/document/d/10fmlEYIHcyead_4R1S5wKGs1t2I7Fnp_PaNaa7XTEk0/edit#) - a spec & collection of Java annotations for interoperability with JavaScript. A way to “consume” existing JavaScript libraries as well as to export Java code for consumption from JS
- jsinterop-generator (https://github.com/google/jsinterop-generator) - a project able to parse Closure-extern files and generate jsinterop-annotated Java interfaces for consuming existing JavaScript libraries. Might support ts.d files in future as well
I think philosophically, Google recognizes that nowadays languages other than JavaScript are all niche players in the contemporary JavaScript stack, so they need to interoperate very well with it rather than replace it (as GWT tried) with an “end all solution” that falls under its own weight as nobody has the time to maintain it.
(… not that they had any other option in 2006, when Webpack, TypeScript, React etc. did not even exist - but the world is quite different in 2017.)
To make the interoperability between Java and Kotlin as smooth as possible, Kotlin and J2CL must not only interoperate on the jsinterop level - a closer integration might be necessary, where I am not supposed to annotate a Java class with jsinterop annotations so as to use it from within Kotlin. That probably means that J2CL and Kotlin have to somehow “agree” on using common name mangling scheme when transpiling overloaded methods to ES6. I’m sure I’m missing a lot of additional details here.
Thoughts?