Thanks <@U1ENTFTA4>, but if `Unit` is the `void` e...
# getting-started
h
Thanks @marstran, but if
Unit
is the
void
equivalent, why is it assignable in kotlin but not in java?
r
This is a misunderstanding.
Unit
isn't the
void
equivalent. The problem is
void
in Java is playing two roles and doesn't distinguish between them. Java can't distinguish between a function that returns, but doesn't return a useful value (
Unit
in Kotlin
()
in Rust, etc.) and a function that doesn't return at all (usually called a diverging function) (
Nothing
in Kotlin,
!
in Rust, etc.)
Basically,
Unit
+
Nothing
is the equivalent of Java's overly vague
void
.