Comparing two comparator objects in Java
<p>If I do the following </p>

<pre><code>myObject.myMethod(myClass.getComparator());
</code></pre>

<p>with</p>

<pre><code>public void myMethod(Comparator&lt;? super myOtherObject&gt; comparator) {
if (comparator.equals(myClass.getComparator()) {
 //do sth
}
}
</code></pre>

<p>and in myClass</p>

<pre><code>   static Comparator&lt;ListItem&gt; getComparator() {
        return new Comparator&lt;myOtherObject&gt;() {
            public int compare(myOtherObjectitem1, myOtherObjectitem2) {
                return (Integer.valueOf(myOtherObject.getRating()).compareTo(Integer.valueOf(myOtherObject.getRating())));
            }
        };
    }
</code></pre>

<p>then "//do sth" is not gonna be executed. So the objects I get from getComparator the two times are different. How can that be? Is there a chance to see, which comparator "myMethod" gets?</p>
