Null object: Difference between revisions
m
→{{header|Ecstasy}}
Line 738:
String? s = Null; // "String?" is shorthand for the union "Nullable|String"
String s2 = "test";
console.print($"{s=
// Int len = s.size; // <-- compiler error: String? does not have a "size" property
Int len = s?.size : 0;
console.print($"{len=
if (String test ?= s) {
Line 752:
// 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=
}
}
Line 760:
<pre>
Null value=Null, Null.toString()=Null
s=Null, s2=test,
len=0
s=a non-null value, s2=a non-null value,
</pre>
|