Ruckus
12/30/2021, 5:40 AMtypealias Null = Nothing?
to the stdlib (and preamble)? Common use case:
class Info<T>(val description: String, val payload: T, ...)
interface Base<T> {
fun getInfo(): List<Info<T>>
}
class Derived: Base<Null> {
override fun getInfo() = listOf(Info("...", null, ...), ...)
}
IMO it reads easier than class Derived: Base<Nothing?>
.
(Yes, I understand I could use Unit
in this case to achieve basically the same thing in this contrived example. That's beside the point.)ilya.gorbunov
12/30/2021, 3:50 PMNothing?
is used and where Null
would be more expressive?ilya.gorbunov
12/30/2021, 3:52 PMNull
can be a typealias to Nothing?
, and Nothing?
can be considered as a union of Nothing | Null
ilya.gorbunov
12/30/2021, 3:55 PMNull
identifier in a package imported by default would be rather disturbing. There can be objects named Null
(https://github.com/pact-foundation/pact-jvm/blob/7cd4ff4d3be7f8e4a3534ae67c3ef18d0b998dc8/core/support/src/main/kotlin/au/com/dius/pact/core/support/json/JsonValue.kt#L41) and they can lead to a conflict or confusion when being in scope with the Null
typealias.Ruckus
12/31/2021, 8:38 AMNull
is probably a common class name for a number of serialization / data interchange libraries.
As far as how many cases there are (where Nothing?
is used and where Null
would be more expressive), I'm not sure how to gauge that. While I use it in a number of my projects, the use case is admittedly pretty niche. I'd guess that most cases where Nothing?
is used, Null
would be more expressive (at least I can't think of a good counter example right now).Ruckus
12/31/2021, 8:53 AMNull
altogether, and have null
be both a value and a type, though then it feels like we're stepping on `Unit`'s toes a bit.