r/learnjava • • Oct 25 '22

What does this method really do

I have always used this code and I am not sure what it really does especially dealing with the o

public int compareTo(BasketballPlayer o) {

return averagePPG - this.averagePPG;

}

What does the o mean in the code. I know its a method but I do not know how it is different from the a normal method thats like

public int compareTo() {

return averagePPG - this.averagePPG;

}

0 Upvotes

3 comments sorted by

View all comments

3

u/nogain-allpain Oct 25 '22

In your code, o doesn't even mean anything, since you're not using it in the body of the method. I presume you mean to do something like:

return this.averagePPG - o.averagePPG;

which returns a positive number if your object has a greater PPG than o, or a negative one if o has a greater PPG.