Name: nt126004 Date: 07/31/2002
FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
FULL OPERATING SYSTEM VERSION :Microsoft Windows XP
[Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
I have searched the bug database using "most specific
method" (exact phrase) and "maximally" and find no bug
reports that cover this
In JLS 15.12.2.2 there is no distinction whatsoever
between static and non-static methods. Class methods do
not conform to the following line of the spec
T can be converted to U by method invocation conversion
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. compile and execute the code as provided
2. remove the static keyword from the overloaded test
methods
3. recompile
EXPECTED VERSUS ACTUAL BEHAVIOR :
The code should not compile as provided. The expected
results are what you get when the static keyword is
removed from the overloaded method declarations. Instead
it compiles and prints "test(int i)"
ERROR MESSAGES/STACK TRACES THAT OCCUR :
HERE IS THE EXPECTED TEST RESULTS:
Test.java:3: reference to test is ambiguous, both method test(int) in
Superclass and metho
d test(long) in Subclass match
new Subclass().test(0);
^
1 error
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
class Test {
public static void main(String[] args) {
new Subclass().test(0);
}
}
class Superclass {
static void test(int i) {
System.out.println("test(int i)");
}
}
class Subclass extends Superclass {
static void test(long l) {
System.out.println("test(long l)");
}
}
//This program compiles and when executed prints test(int i).
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
An abscure problem found in preparing a textbook. Class
methods are seldon overloaded.
(Review ID: 160093)
======================================================================