Operator == with null operand [message #1795053] |
Thu, 13 September 2018 15:53 |
|
Dear all.
I have defined several extension methods (which are implicitly imported):
def boolean operator_equals(AtomicLong left, int right) {}
def boolean operator_equals(AtomicLong left, short right) {}
def boolean operator_equals(AtomicLong left, long right) {}
def boolean operator_equals(AtomicLong left, float right) {}
def boolean operator_equals(AtomicLong left, double right) {}
def boolean operator_equals(AtomicLong left, byte right) {}
def boolean operator_equals(AtomicLong left, Number right) {}
def boolean operator_equals(AtomicInteger left, int right) {}
def boolean operator_equals(AtomicInteger left, short right) {}
def boolean operator_equals(AtomicInteger left, long right) {}
def boolean operator_equals(AtomicInteger left, float right) {}
def boolean operator_equals(AtomicInteger left, double right) {}
def boolean operator_equals(AtomicInteger left, byte right) {}
def boolean operator_equals(AtomicInteger left, Number right) {}
The following line is compiled without error:
def void fct(AtomicInteger value) {
if (value == null) {
}
}
But the following line causes a compilation error (ambiguous feature call):
def void fct(AtomicInteger value) {
if (null == value) {
}
}
As you could see, the operands of the == operator are switched.
Semantically, both definitions are equivalent.
My question is: what is the best way to support the failing case?
Is possible to define an operator_equals function and specifying that this function is usable when the left argument is null?
Should I define operator_equals(Object left, Number right)? In this case, the type compiler of Xbase hould be fixed to avoid the ambiguous feature call error.
What do you think?
All the best.
Stéphane.
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03525 seconds