I thought you might like to see this &quot;bug&quot; someone called to my attention recently.  I don&#39;t know if it is a spec issue or a <span class="il">compiler</span> issue.<br><br>Cheers,<br>Neal<br><br>===========================<br>




<p><span style="font-size: 10pt; color: black;">Hi
Neal,</span></p>

<p><span style="font-size: 10pt; color: black;"> </span></p>

<p><span style="font-size: 10pt; color: black;">I
wonder if you might be interested in considering a possible Java bug?</span></p>

<p><span style="font-size: 10pt; color: black;"> </span></p>

<p style="margin-left: 40px; font-family: courier new,monospace;"><b><span style="font-size: 10pt; color: black;">package
pck;</span></b></p>

<p style="margin-left: 40px; font-family: courier new,monospace;"><b><span style="font-size: 10pt; color: black;"><br>
abstract class C&lt;T&gt; {<br>
    public abstract Object foo(T x);<br>
    public Integer foo(String x){ return 1; }<br>
    public void bar(T x){<br>
        System.out.println(foo(x));<br>
    }<br>
}</span></b></p>

<p style="margin-left: 40px; font-family: courier new,monospace;"><b><span style="font-size: 10pt; color: black;">class
D&lt;T&gt; extends C&lt;T&gt; {<br>
    public Object foo(T x) {<br>
        return 2;<br>
    }<br>
}</span></b></p>

<p style="margin-left: 40px;"><span style="font-size: 10pt; color: black;"><b><span style="font-family: courier new,monospace;">class
E extends C&lt;String&gt;{</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
    public static void main(String args[])</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
    {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
        new E().bar(null);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
    }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
}</span></b></span></p>

<p><span style="font-size: 10pt; color: black;"> </span></p>

<p><span style="font-size: 10pt; color: black;">This
code compiles successfully and... what do you think it prints?</span></p>

<p><span style="font-size: 10pt; color: black;">But
if I reorder foo methods in C&lt;T&gt;, then the behavior changes.</span></p>

<p><span style="font-size: 10pt; color: black;"> </span></p>

<p><span style="font-size: 10pt; color: black;">Is
it a bug? What is by-design behavior for this code?</span></p>