Java Java Data Structures Organizing Data Interfaces

Guillaume Cartier
Guillaume Cartier
2,860 Points

in compareTo method, why can't we pass a treet as parameter instead of an object ?

public int compareTo(Treet other) { ....


public int compareTo(Object obj) { Treet other = (Treet) obj; ....

1 Answer

Pedro Cabral
Pedro Cabral
23,292 Points

You can use:

compareTo(Treet other)

if you implement Comparable parameterised to the Treet class with:

public class Treet implements Comparable<Treet> {