4 ms·
It's not possible in Kotlin to have an instance of Nothing, and the compiler does some magic for the Nothing type, in that it can be converted to any other type
by greiskul 7y ago
It's not possible in Kotlin to have an instance of Nothing, and the compiler does some magic for the Nothing type, in that it can be converted to any other type in the system (so it's like the opposite of the Any type). This allow code patterns like:
'''
val personName = person.name ?: throw IllegalArgumentException("Name required")
'''
Where the type of personName is now String, cause if name was null it would throw an exception (and the type of a throw expression is Nothing).