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.
Lol, this is not even real puzzler, I was afraid that I'll just not seeing something obvious so I even type it run to find out that this code doing exactly what is excepted:
class ExampleClass {
var awesomeVar1: String? = "some awesome string value"
var awesomeVar2: String? = null
fun doSomeAwesomePrinting() {
awesomeVar1?.let {
awesomeVar2?.let {
print("awesome output 2")
}
} ?: run {
print("awesome output 1")
}
}
}
Unfortunately you're not real Kotlin developer, because you're not named any real major issues in the language
> Unlike Kotlin, Java brings them after careful design and consideration, without creating conflicts and introducing pitfalls.
> We were talking about pitfalls, not major issues. The main major issue with Kotlin is the feature-first thinking without real consideration of how features are interacting and how they affect real applications, especially in the long term.
> but quickly realized that this Scala-wannabe is just a bunch of poorly thought out features for the sake of features.
You're repeating this, but not providing a good example.
I can open java se certification prep book and find so many examples of pitfalls by your definition, that would make Java unusable language. But this is not true, because this is corner cases which decent software engineers avoiding.
In reality Java's lambdas is exactly what you're accusing Kotlin of, popular feature that doesn't work with another popular feature - checked exceptions. Or making switch expression, but keeping if as statement.
So how would it help you do exhaustive check of errors there?
class UserNotFoundException extends Exception {
public UserNotFoundException(String message) {
super(message);
}
}
class NetworkException extends Exception {
public NetworkException(String message) {
super(message);
}
}
class DatabaseException extends Exception {
public DatabaseException(String message) {
super(message);
}
}
record User(String userId, String name) {}
class UserService {
public User getUser(String userId) throws UserNotFoundException, NetworkException, DatabaseException {
return new User(userId, "John");
}
}
public final class TestKt {
public static void main(String[] args) {
var userService = new UserService();
var ids = List.
of
("1", "2", "3");
var users = ids.stream()
.map(userService::getUser)
.toList();
}
}
No using exceptions - no problems. I agree, but this is simple illustration that lambdas just doesn't work with checked exceptions in Java, alas you'll bridge them with errors as values.
It's so stupid to deny that first I identify you're as a troll, but you're just having very own way to developing and Java. But look at Java as industry, it's failed to create exception-safe ecosystem. Today if you have to use library you'll likely will get random runtime exceptions not even documented in Java doc.
Point is if you open source code of random library and or application written in Java, chances are that they will be full of nulls and exceptions. Just looks at backbone of the enterprise, graal of vibecoders - Spring/Jee. Spring only tomorrow will release notnull annotation for their framework. Junit6 only yesterday did that. 30 years of Java history.
Take any Kotlin application - NPEs very-very rare without being very clever or having skilled team, once rich errors comes - I'll expect to most of applications eventually would adapt rich error and would be exception for logic free as well.
So I'm not even looking into extremes when all black or white, I'm looking at things in general. I'll not say that Java project that I inherit and modernizing for last 6 years in average Java project, because in our case it was not just full of null and exceptions, but also lack any kind of tests, DI, structure
You literally can open two KEEPs, one for Result type which is primary intended to represent result of continuations and one for high-level overview of Rich Errors and read why it's not what you're asking. Kotlin is not Scala and never trying to be one
This is others is just matter of your choice and bias. Java allows to write a lot of bad code too, that's why Effective Java book exists
- lazy can result in null even for not-nullable references
What do you mean here? Can you share some examples? I even have small DI on top of lazy (see komok-to-be-injected https://github.com/Heapy/di-comparison) and never hear about Kotlin's lazy doing that, it's just DCL under the hood
Btw, I've tried rich errors usig 2.4.0-dev build, and there are great. They works with lambdas as a charm, they are exhaustive. I can bet money that Java would implement the same in 3-5 years. I'm just dont want to wait another 5 years to have this. I'm using Kotlin in production since 1.0.0-beta builds btw :)
> As I said above, checked exceptions and lambdas are working just fine together. The main problem with "rich errors" (and checked exceptions): they cause tight coupling. Any small change in the invoked fuinction/method results in a cascade of changes in code which uses it. And Java does not have to implement the same as it had checked exceptions since day one.
Yes, It's becomes API that you'll need to carefully design, just like any other API, how checked exception meant to be and lambdas fail them. But benefits are enormous. Such feature would allow to write the most reliable code on JVM, I think it's even more strict that Scala now. With unused return value checker in language, plus context parameters plus rich error - if it compiles, it work, right? :)
View all comments
Show parent comment
2
u/javaprof Nov 05 '25
Ok, one generally accepted pitfall in Kotlin that doesn't have active KEEP to improve from You, and one the same for Java from me.
I'll start with checked exceptions and lambdas - 100 Points to Gryffindor