creating an object and defining method at the same time
<p>Is it possible to declare a method while creating an object? I ran across the following lines of code in java:</p>

<pre><code>public static void main(String[] args) {
        Comparator&lt;String&gt; comparator = new Comparator&lt;String&gt;() {
            public int compare (String s1, String s2) {
                return s1.compareToIgnoreCase(s2);
            }
        };
}
</code></pre>

<p>And it looks like that while creating the object <code>comparator</code>, the code is adding a method to implement the <code>Comparator&lt;T&gt;</code> interface. Is adding additional methods always possible when creating instances, or is it something in particular that's related to a java interface?</p>

<p>Thanks for any help!</p>
