I have a class that implements the Comparable interface. In this class I need to override compareTo method in order to sort objects by Long
values.
What I don't know is how to perform is the comparison of the Long type. I get error when trying to check if value is greater than or less than another Long value. I know Long is the object of long, but have no idea how to compare two Long's.
Code sample:
public int compareTo(MyEntry<K, V> object) {
if (this.value < object.value)
return -1;
if (this.value.equals(object.value))
return 0;
return 1;
}
Error message:
operator < cannot be applied to V,V
if (this.value < object.value)
^
V, V is Long, Long
compareTo
method inLong
– Zeeba