Is the compareTo (in the Comparable interface) recursive?

advertisements

I am implementing the Comparable interface, and using it to compare the names of sports teams. I noticed that this was the simplest implementation of the compareTo method. I was wondering why the method compareTo refers to itself in the body of the method. Isn't that some sort of never-ending recursion? How can you implement a method by defining it as itself?

public int compareTo(Team x)
{
    return teamName.compareTo(x.teamName);
}


You don't present the complete code that puzzles you, but presumably the method you do present belongs to a class Team of some package, and presumably that class's teamName field is of a type different from Team (I'll suppose it's java.lang.String). In that case, the method you present is not recursive at all. Method some.package.Team.compareTo(some.package.Team) invokes method java.lang.String.compareTo(java.lang.String), which is a completely separate method.