i have the following code for handling default values when a lookup returns null
def user = User.find('admin')
return user?.address?user:null
this works as expected
however when using the Elvis operator like:
def user = User.find('admin')
return user?.address?:null
i get an exception thrown:
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'true' with class 'java.lang.Boolean' to class 'com.code.User'
I was expecting Elvis to behave exactly like the ternary operator….?
thanks!
This returns
userif the user is not null anduser.addressevaluates totrue:This returns
user.addressif the user is not null anduser.addressevaluates totrueI assume
user.addressis a boolean? So the second one is trying to return a boolean probably from a method you say returns aUserin the definition