Null object: Difference between revisions
m
→{{header|Ecstasy}}
Line 730:
<syntaxhighlight lang="java">
module NullObject {
void run() {
@Inject Console console;
console.print($"Null value={Null}, Null.toString()={Null.toString()}");
Line 746 ⟶ 744:
console.print($"len={len}");
if (String test ?= s) {
// "s" is still Null in this test, we never get here
} else
s = "a non-null value";
// if (String test ?= s){} // <-- compiler error: The expression type is not nullable: "String"
s2 = s; // at this point, s is known to be a non-null String
console.print($"s={s}, s2={s2}, (s==s2)={s==s2}");
}
}
</syntaxhighlight>
|