I use a Java method that returns an object or null if a value was not found. So I need to check for null values:
val value = javaobject.findThing(xyz)
if(value != null) {
value.doAnotherThing()
} else {
warn("Value not found.")
}
Can I write this code shorter with the Box concept? I have read the Lift-Wiki-documentation about the Box concept, but I don’t understand how to use it with Java null values.
@TimN is right, you could use
Box(value)to create aBoxfrom a possiblynullvalue, but you’ll get a deprecation warning.While you could use
Box.legacyNullTest, if this is what you’re doing, then I would just stick with the standard library and useOption.And if you needed a
Boxto pass around,Optionwill automagically convert to aBox: