Outside of Android I wouldn't choose Kotlin.
Outside of Android I wouldn't choose Kotlin.
Lambdas can't handle checked exceptions, which are the most common exceptions in the system.
There is no way to extend Stream with your own methods.
Still 8 primitive types to wrestle with.
Just to name a few issues. And there are lots and lots more.
The language is simply not extensible enough to write anything elegantly.
() -> {
try {
// do work
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
}
I also agree with Goetz that extension functions aren't something we need.Regarding extension methods, while they are nice, with import static it just a matter where the extended type comes, big deal.
And from experience in .NET world, hunting them down isn't always fun, even if they are just Ctrl+F12 away.
You can do exactly the same thing that Kotlin would do for you and just rethrow them as runtime exceptions. It's one extra wrapper call; not great, but not a huge overhead either.
> There is no way to extend Stream with your own methods.
That's just syntax sugar; all it's actually doing is calling a static method, which you can still do in Java.
> Still 8 primitive types to wrestle with.
You can just ignore them and use the object versions everywhere, and then it's not a problem.
There are a bunch of irritating warts in Java, but irritating warts alone are not worth switching language over.
i kinda get how this is safer, but clients can just call optionalRef.get() without checking, and boom there goes the safety. compiler warnings be damned.
You could also do this in Kotlin and boom there goes the safety:
fn nonNull(): String {
val s: String? = null
return !!s
}For back-end service/API type things in an enterprise setting, Kotlin is a good value proposition. There's also probably some truth to the idea that one reason modern Java is adding these things is because of Kotlin's existence.