I thought you might like to see this "bug" someone called to my attention recently. I don'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<T> {<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<T> extends C<T> {<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<String>{</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<T>, 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>