私が次のことをすると
myObject.myMethod(myClass.getComparator());
と
public void myMethod(Comparator<? super myOtherObject> comparator) {
if (comparator.equals(myClass.getComparator()) {
//do sth
}
}
とmyClassで
static Comparator<ListItem> getComparator() {
return new Comparator<myOtherObject>() {
public int compare(myOtherObjectitem1, myOtherObjectitem2) {
return (Integer.valueOf(myOtherObject.getRating()).compareTo(Integer.valueOf(myOtherObject.getRating())));
}
};
}
その場合、「//dosth」は実行されません。したがって、getComparatorから2回取得するオブジェクトは異なります。どうしてそれができるのでしょうか?どのコンパレータ「myMethod」が取得するかを確認する機会はありますか?