I am trying to understand below statement came across code in my project
if(name != null && +ssnCount.getLongValue > 0){
......
}
Can some one explain me +ssCount.getLongValue mean? and difference. Thanks for you time.
I am trying to understand below statement came across code in my project
if(name != null && +ssnCount.getLongValue > 0){
......
}
Can some one explain me +ssCount.getLongValue mean? and difference. Thanks for you time.
- Unary plus operator; indicates positive value (numbers are positive without this, however)
Actually there is no significant difference between an number variable and an number variable prefixed with the unary operator plus. It is interesting that this operator unboxes wrapped values to primitive types. For example if you declare:
Integer a = 10;
then using the reference 'a' will be of the reference type Integer, but using '+a' will be of the primitive type int. To be clearer:
Integer a = 10;
System.out.println(a instanceof Integer);// true
System.out.println(+a instanceof Integer);// compile time error - unexpected type
This looks like damaged code. The () after getLongValue is missing (I presume that, with that name, it was intended to be a function call), and unary plus is VERY rarely used.
I'd suggest taking it back to whoever wrote it, pointing these issues out to them, and asking them what they had in mind.