Elvis operator
Alex Buckley
Alex.Buckley at Sun.COM
Thu Jul 16 11:35:11 PDT 2009
Dierk,
Thank you very much for writing.
Putting ?: and ?. side-by-side shows they are dual in a type-theoretic
sense. ?: returns a specific value of a specific type (indicating a
default), while ?. returns a non-value of the bottom type. Since the
bottom type is a subtype of all other types, the non-value will swallow
all messages sent to it. The non-value turns into the null reference at
assignment conversion or method invocation conversion, of course.
Turning to more practical matters, do you have a sense of how often ?.
is used in Groovy code? Why would anyone dereference with '.' when they
could use '?.' ? If '.' is still commonly used, is Groovy code littered
with as many == comparisons with null as Java code is?
Alex
More information about the coin-dev
mailing list