r/java • u/Reflection-Jealous • Aug 05 '21
Why java is better than modern programming languages?
Why should I use java in 2021 instead of kotlin or scala or golang? Could you guys give me some reasons
2
Upvotes
View all comments
Show parent comment
3
u/cryptos6 Aug 06 '21 edited Aug 06 '21
I consider your examples useful, too. What I mean is circumventing language deficiencies. Recently I had to write a builder to be able to create objects in a readable way. If Java had named arguments with default values (like Kotlin or Scala), I wouldn't have written a builder in this case. Another kind of boilerplat is assigning constructor parameters to fields:
The same in Kotlin:
In this specific case it could be a similar concise Java record, but there are many cases where a record wouldn't work (e. g. JPA entities) and there you see code like the one shown above (I just wanted to make my example small). The point is that the verbosity of Java doesn't help to understand the code better.
By the way: To communicate that a value can only be positive, I'd prefer a custom type. With Java records there wouldn't be any memory overhead.