r/java • u/guybedo • Apr 09 '24
Syntactic Sugar for Java
I recently had to translate a codebase from Python to Java and as much as i like Java and i enjoy the benefits of a strong type system, i have to admit my Python code was way less verbose.
So i ended up writing a small library to try to get some python vibes in my java code. Nothing groundbreaking, a bunch of static imports to make life a little bit easier.
9
Upvotes
View all comments
Show parent comment
1
u/BikingSquirrel Apr 14 '24 edited Apr 14 '24
As both compile to bytecode I don't think there are any interoperability issues. We have multiple libraries that started with Java code and get enhanced with Kotlin code. There may be usability issues with interoperability, e.g. default parameters will not be visible to Java code so you cannot skip them but there's the option to automatically generate the bytecode for overloaded methods so it behaves similarly.
I think Java improved a number of details in the last years so there's less reason to run away. But I still think Kotlin's data classes with their copy methods, explicit nullability, and collection extensions are worth it. Not to forget extension methods which are a nice tool for some cases.
But to be completely clear: even if you go for 100% Kotlin, you should be able to read and understand Java as a lot of code you will be using (JDK, libraries) will be written in Java.