Reputation: 39
Some backstory, I am getting a warning for some code that I wrote. The warning and the two code excerpts are below. Are they just telling me to use !.equals()
method instead of !=
when comparing the two references in the if statement? minRange
is a short
Questionable use of reference equality rather than calling equals. Suspicious comparison of short references
if (minRange != other.minRange)
return false;
Both these excerpts are unrelated but the warning showed up twice
if (mod_system.getMaxRange() != (current_system.getMaxRange()
changed_data = true;
Upvotes: 0
Views: 112
Reputation: 5980
I presume you variable types are Short
, in which case ==
will only compare references, not values.
So to answer your question, yes you should be using .equals(Object)
, which unboxes their primitive values for comparison. Otherwise you could do the unboxing yourself with:
minRange.shortValue() == other.minRange.shortValue()
Upvotes: 2