I have a Pair class of Generic Type and the following way of subtraction gives me error as the operator - is not defined for T,T
. I searched and found that link. I wonder it is the only way of operator overloading in Java. I think not straightforward. I came from C++ background. Thanks
public class Pair<T>{
private T first;
private T second;
public T firstpairSub(Pair<T> s) {
return this.first - s.first;
}
}