But,we have to call compareTo within compareTo when Comparable is implemeted.
Then,it means it should always give the StackOverflowError
Not always do you have to call the compareTo method within the compareTo method.
And even if you do, it isnt the comapreTo method of the current class that should be called since tht would be a recursive call to stack overflow
Rather the call should be a compareTo call of the constituent fields of the current class.
For eg if your code would get modified as below
new Integer(this.field).compareTo(((A)o2).field);
This part of the code wraps the current field object and compares it with the field of the object passed as arguement (using autoboxing).
It does this with the help of the compareTo method of the Integer class and not the current class.