Is there any way to use autoboxing for the classes I create? For example, I have this subclass of Number
.
public class UnsignedInteger extends N
If you use Groovy, you can set the boolean behavior by implementing the asBoolean method: http://groovy-lang.org/semantics.html#_customizing_the_truth_with_asboolean_methods
Example:
class Color {
String name
boolean asBoolean(){
name == 'green' ? true : false
}
}
assert new Color(name: 'green')
assert !new Color(name: 'red')
I know this is not plain Java but compiles to bytecode and runs on the JVM.