Is there a way to tell the Kotlin compiler to trea...
# announcements
r
Is there a way to tell the Kotlin compiler to treat certain Java methods with a
void
return as
Nothing
instead of
Unit
?
b
That would break the type system.
void
is isomorphic to
Unit
- they are both sets with exactly one element - whereas
Nothing
is a set with zero elements. There would be no way for Java to interoperate with Kotlin if
Nothing
was used in place of
void
.
The type checker needs to be able to understand it and they are fundamentally different types
Eh, my guess is writing something to handle that special case of Java not really having an official Nothing type wasn't a high priority for the Kotlin roadmap
Strangely enough it's possible to express what you want in Kotlin with enough function wrapping, although IJ warns that the call is "unreachable code"
That seems like an easier solution than adding exceptions to the type system