JAVA I have The operator is undefined for the argument type
(JAVA)
I have \'The operator - is undefined for the argument type(s) Integer, Integer\'.
Here is my code:
==================
import java.util.Comparator;
public class Integer implements Comparator<Integer> {
   @Override
    public int compare(Integer int1, Integer int2) {
        return int1 - int2;// error occurs in this line
    }
 }
Solution
Hi Friend, Integer is your defined class. You need to define the meaning of (-) operator for your class.
Please see my one of the implementation.
Lets assume there is a instance variable, called \"value\" in your Integer class, then you can simpy implement
\'compare\' method like this.
Please let me know in case of any issue.
import java.util.Comparator;
public class Integer implements Comparator<Integer> {
// instance variable
private int value;
// others instance variables and methods
///
@Override
public int compare(Integer int1, Integer int2) {
return int1.value - int2.value;// error occurs in this line
}
}

