Community
Participate
Working Groups
The elvis operator effectively allows to provide a default value in case an expression evaluates to 'null'. Example : someStringOrNull :? 'hello' I propose to do this via library using an extension method on java.lang.Object. someStringOrNull.ifnull['hello'] @rrmckinley suggested via twitter to use a shorter more readable name like 'or' or 'else'. Unfortunately 'else' being a keyword won't work and 'or' could be surprising since as it would be defined on Object the following expression would result in 'false': false.or[true] Any other suggestions?
I agree with you that 'or' is a bad surprise. I rescind! ;-) Null should be in the method name to be the best guide.
I find ifNull the most intuitive name. IMO 'else' or 'or' are not descriptive enough and I don't think that we really need a shorter name than ifNull.
Available in 2.3
Requested via bug 522520. -M.