Hi all,
do you have experience in converting Java-files with for instance IntelliJ to Kotlin? Would I have to make a lot of changes for having idiomatic Kotlin code?
Probably I first start with a smaller module from a multi-module Maven-project :-)
kind regards
Johannes
Top comments (2)
In my experience the tool for converting inside of IntelliJ is a good initial approach but strangely is not the most idiomatic thing and sometimes it adds weird stuff because it doesn't know too much on the context of a variable on Java.
So my recommendation is to just try to move from java to kotlin using what you know from the language, let's call this process "write kotlin in the java way" so you can get used to things in Kotlin and understand when you need a
String
vs.String?
The IDE will give you good suggestions on what can be changed from
var
toval
and other kind of stuff (merge definition with assignment, remove useless blocks of code, add operators, etc.)That's the best way to get used to the language, believe me, going in to more idiomatic takes time, not much, but still time. So it's best to get used to get used to the language and later optimize
Thanks, I've already written a Vert.x Kotlin-based RESTful API for the project -- just calling the Java core-module and other modules from Kotlin code and it works like a charm -- maybe it's not straight forward the other way around to call Kotlin methods from Java, but that's not needed as of now.
My code certainly might also not be perfect idiomatic Kotlin code, but I guess it's okay, as IntelliJ offers quiet some refactoring stuff. That said I'd be more than happy to have another eye on the code (if someone is interested, it's Open Source ;-)). Especially on the coroutine stuff.
Thanks a lot for your suggestions. I'll probably move a smaller module, I'm not sure though. Maybe another way would be to simply put a Kotlin based API on top, but then I still have to use Java ;-)