的,我有以下接口:接口方法採取相同的實現接口
public interface ClusterPopulation
{
public double computeDistance(ClusterPopulation other);
}
是否有可能接口本身內指定,ClusterPopulation的是實現一個只能拿一個實現作爲computeDistance的說法?
唯一approching的解決方案,我看到的是下面的,但我不喜歡它:
泛型接口重新定義:
public interface ClusterPopulation
{
public <T extends ClusterPopulation> double computeDistance(T other);
}
內執行,拋出IllegalArgumentException如果從參數不好的類型,如果類型沒問題的話可以做一些演員...... Meeeeh!
即使使用這種方法,最終用戶只知道約束的閱讀文檔/查看代碼執行/試錯...
任何更好的解決方案?
http://stackoverflow.com/questions/7354740/is-there-a-way-to-refer-to-the-current-type-with-a-type-variable – biziclop