I have the following interface :
public interface ClusterPopulation
{
public double computeDistance(ClusterPopulation other);
}
Is it possible to specify within the interface itself, that implementation A of ClusterPopulation can only take A implementation as argument of computeDistance ?
The only approching solution that I see is the following, but I don't like it :
Redefine interface with generics:
public interface ClusterPopulation
{
public <T extends ClusterPopulation> double computeDistance(T other);
}
Within the implementation, throw IllegalArgumentException if argument is not from the good type, do some casts if type is ok... Meeeeh !
Even with this approach, end-user is only aware of the constraint by reading the documentation/looking at code implementation/trial and error...
Any better solution ?