|
|
|
|
|
by ptx
2608 days ago
|
|
You would still have null, but only when asked for and checked explicitly. In Kotlin, for example, you mark something with a question mark to say that it can be null, which forces you to check for null before using it: val entityOrPossiblyNull: Entity? = Entity.fetch(id)
if (entityOrPossiblyNull == null) {
doSomething()
}
else {
// The compiler knows that the variable is not null in this branch,
// so this assignment is OK.
val entityForSure: Entity = entityOrPossiblyNull
doSomethingWithEntity(entityForSure)
}
|
|