Interface name of the same name corresponding to the type of the method parameter

public interface TreeValue {
   public boolean lessThan(TreeValue value)
}

Hello everybody,

I came across this example and I have no idea why the TreeValue in the method has the same name as the interface. Why not int? What is the advantage of using the same name as the interface?

Thank!

+4
source share
2 answers

The idea is that this method lessThancompares two objects of a tree value. This is similar to equalsany methodObject

+3
source

This is no different from the signature of the object equals...

public boolean equals(Integer otherInteger)

... or implementationcompareTo (where Tdefined as Long).

public int compareTo(Long otherObject)

, , TreeValue, . TreeValue -like, .

. , , , , , .

+1

All Articles