by gavinray · 3y ago · 0 comments
- Pattern matching
- Sealed types
- Records (immutable, succinct data-classes)
- Multiline strings
Among other things. It's almost as nice to use as Kotlin, and I say this as a huge Kotlin fan. Its pattern matching in most recent releases is actually more powerful than Kotlins, since it allows deconstruction-bindings in patterns.
Since Java's history is very focused on not breaking things (and folks got really grumpy on the few occasions something has been broken), Java cannot ever match the feature pace of languages like C# either.
But the folks writing Java code (most of you here on HN by all metrics), mostly don't care. They enjoy backwards compatibility and stability far more than new features. The overwhelming majority of newly written Java code is targeting Java8 still - which doesn't use any of these new features anyway.
Backwards compatibility is also why things like lambda's and streams are the way they are in Java (and most FP folks would sneer at), and things like Records took years to release (still technically in the Preview stage).
The advantage Kotlin has, and the reason it's growing in popularity in backend development is you get all the FP tasty features you want right now, but maintain near drop-in compatibility with existing Java libraries and frameworks. This was the most brilliant move by the Kotlin designers in my opinion...
Java 8 users are now a minority. Some libraries still target it (although Spring 6 targets 17 as the baseline), but most Java code is in applications.
> Java can never be Kotlin
Java doesn't want to be Kotlin because it aims at a much wider audience. Back in the nineties James Gosling laid out a strategy of an innovative runtime wrapped in a conservative language that only adds the most beneficial features, and only after they've been successfully tried in other languages, and this has worked very well.
Also, the Java language has the advantage of controlling the runtime, which allows us to add a smaller number of features, which are more powerful (e.g. compare records with data classes, or virtual threads with syntactic coroutines), while Kotlin can neither change the runtime nor have a significant impact on the ecosystem, and so is more limited in what it can achieve. Moreover, Kotlin's features are increasingly mismatches with the evolution of the platform.
Nevertheless, we are happy that the platform offers more feature rich languages to the minority of developers that do prefer them (or languages with radically different approaches, such as Clojure), so the platform can cater to programmers with different language preferences.
That's by deliberate choice. They are going down the route of having the last mover advantage. Lots of people have complained about C#'s kitchen sink type of approach for example. And the more features you have, the more chance that they won't fit together neatly and cleanly.
A couple of examples that come to mind, Java's pattern matching/destructoring and upcoming string templates (JEP 430) are much more fully fledged compared to their Kotlin counterparts.
It also has the advantage of being the platform language. Now that we have virtual threads on the JVM, async/await immediately becomes irrelevant. However, Kotlin now has to maintain coroutines even though the platform offers a better way of doing things.
The amount of syntax I see literally 1:1 taken over by dozen other languages is really impressive and evidence for that.
Thank God. Don’t get me wrong, C# is a cool language but languages suffocate under so many features, most devs will simply never ever learn most of them. And some of these features while invaluable in certain rare cases, I would rather prefer a better, more fundamental feature that takes more time and single-handedly solves for many situations.
Unfortunately modern languages really like to throw in everything they have seen from other languages ever, and even with very smart language designers these features will inevitably tangle (khm, swift).
The last things missing are properties (which should be coming with reconstructors), and nullable types. For me, nullable types are not worth the switch.
All that being said, I don't think the languages are mutually exclusive. As a JVM developer you retain all your knowledge of the JVM and it's standard library. Lastly, a language doesn't have to be the dominate language on a platform to be usable and employable (just look at Scala).
What Kotlin features are possible because of that freedom ? Genetics can be an example I can’t say it’s impossible for Java to add in out refied keywords