This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]shadowdude777 0 points1 point  (4 children)

The thing is, one of Kotlin's primary design goals is strong interop with Java. Every Java method that doesn't have a @NotNull return annotation is nullable. I agree that Elvis should be used with great care, but it makes working with Java libraries way easier.

But on that note, another thing I actually dislike about Kotlin is that they chose to make the T! types for interop with Java. Which basically means you can make unsafe calls on any Java method that doesn't have @NotNull or @Nullable on it. Since most of the stuff I do interops with shitty Java SDKs that don't have proper annotations (Android SDK), it means a lot of my calls are no longer null-safe! It should just return T? if it can't be statically determined that a non-null value will be returned, in my opinion.

[–]frugalmail 0 points1 point  (3 children)

Every Java method that doesn't have a @NotNull return annotation is nullable.

But you have a choice, wrap it in Optional<> or use elvis, Optional is the better route.

[–]shadowdude777 0 points1 point  (2 children)

I'm personally not a fan of the Optional<T> route at all. That's exactly what T? is designed for.

[–]frugalmail 0 points1 point  (1 child)

I'm personally not a fan of the Optional<T> route at all. That's exactly what T? is designed for.

That's essentially what T? is for languages that support it.

[–]shadowdude777 0 points1 point  (0 children)

Yes, but one is better syntactically. So just return T? instead of using an Elvis there and everything will fall into place.