The biggest java pitfall I can think of (probably the biggest pitfall in any language I've ever enjoyed using) is that every reference is nullable and there's no way around it, the existence of the Optional class, and the Nullable/NonNull annotations introduced in order to cope with this, are akin to having a stop sign where a wall should exist.
Another pitfall is that collection interfaces expose write methods, which immutable implementers are expected to opt out of by throwing a runtime exception (which is quite simply horrible).
Then a minor one is `==` vs `equals`, which tends to bite newcomers in the ass and is not helped by the fact that the first pitfall I mentioned exists.
What do you think a pitfall is? For me, it is unexpected behavior that code produces because the language itself is either unintuitive, obfuscates behavior, or provides poor context (or no context at all) which makes a given snippet hard to reason about. The three examples I gave fit into that meaning. But even if you think they don't, they are still perfectly relevant to the topic of "poorly thought out features" you brought up.
Existence of Optional is good *under* the premise that nullables exist and are pervasive to Java, it's *that* premise that is bad, Optional is only a symptom.
Nullaway, while useful, is not a language feature, but rather a patch that people *have* to know about and apply, so it cannot be used as an argument, (and your advice of "don't use null" is just as valid a counter argument as responding with "just don't do that" to your example of Kotlin elvis operator).
The null problem is not, by any stretch of the word, greatly exaggerated: NPE is the single most frequently uncaught Java runtime exception. And that is not because Java programmers as a whole are somehow more incompetent than Kotlin/Rust/Typescript programmers, it's simply because Java, as a language, makes null inherently easy to make wrong assumptions about.
The gist of my argument is that none of the poorly thought out features of Kotlin come even close in severity to the poorly thought out features of Java (that Kotlin successfully addressed and fixed).
I use Java daily, I work with it, I have orders of magnitude more hours working with Java than I have working with Kotlin (or any language, for that matter), yet I found Kotlin easier to use and reason about after a week of using it.
EDIT: They got the hammer before I could reply lol, here's my response to what they said, for posterity:
No, NPE is far from the most common exception.
Do me a favor and name a more common one.
And Optional is not a symptom of anything. If you disagree, try to explain the existence of Option in Rust, which has no null.
Why do you think Optional is absent from Kotlin? I'll answer: because Kotlin's null already behaves like Optional.
Rust's Option is the same but in the opposite direction: instead of giving direct null handling the ergonomics of Optional, and ditching Optional, like Kotlin did, Rust gave Optional the speed and performance of direct null handling, and ditched null handling. The end result is the same.
Rust's Option<MyType>, and Kotlin's MyType?, exist in place of Java's null. Java's Optional exists on top of null.
Let's put it this way:
null is Java's version of Rust's Option::None.
Optional.empty() is Java's version of Rust's Option::Some(Box::new(Option::None)) (which would make no sense to write in Rust, PRECISELY because Rust's version of null got it right the first time).
And Kotlin didn't address the single Java "poorly thought out features". Even nullability "addressed" by causing more harm than good and still regularly fails to actually prevent NPE.
2
u/Efficient_Present436 Nov 05 '25
The biggest java pitfall I can think of (probably the biggest pitfall in any language I've ever enjoyed using) is that every reference is nullable and there's no way around it, the existence of the Optional class, and the Nullable/NonNull annotations introduced in order to cope with this, are akin to having a stop sign where a wall should exist.
Another pitfall is that collection interfaces expose write methods, which immutable implementers are expected to opt out of by throwing a runtime exception (which is quite simply horrible).
Then a minor one is `==` vs `equals`, which tends to bite newcomers in the ass and is not helped by the fact that the first pitfall I mentioned exists.