I have expression:
Double getAbs(Double value){
return value> 0 ? value: value== 0 ? null : -value;
}
or better:
Double getAbs(Double value){
return Math.abs(value);
}
I understand that there are some differences about NaN. But method Math.abs(double) – so we have unboxing.
In which case performance better?
The only “performance” in your code is that the JVM will need to unbox your
Doubletodouble.Math.abs(double)uses a ternary if statement as follows:So, your
ifstatement is no performance worry at all.