JDK-6559158 : Qualified static method reference reported as ambiguous by javac
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: linux
  • CPU: x86
  • Submitted: 2007-05-18
  • Updated: 2010-04-04
  • Resolved: 2007-05-18
Related Reports
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
ava version "1.6.0_01"
Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Linux nacar 2.6.18-suspend2-r1 #3 PREEMPT Tue Dec 26 21:51:39 COT 2006 i686 Intel(R) Pentium(R) M processor 2.00GHz GenuineIntel GNU/Linux

A DESCRIPTION OF THE PROBLEM :
A qualified reference to a static parametrized class method is reported as ambiguous by javac when the  method hides one in its super class using different type parameters.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the following code:
---
class A {
	public static Object create() {
		return null;
	}
}

class B extends A {
	public static<T>  Object create() {
		return null;
	}
	public static void main(String... args) {
		Object b=B.create();
	}
}
---

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
clean compilation
:)
ACTUAL -
... reference to create is ambiguous, both method create() in A and method <T>create() in B match
                Object b=B.create();
                          ^
1 error
:(

ERROR MESSAGES/STACK TRACES THAT OCCUR :
... reference to create is ambiguous, both method create() in A and method <T>create() in B match
                Object b=B.create();
                          ^
1 error

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
class A {
	public static Object create() {
		return null;
	}
}

class B extends A {
	public static<T>  Object create() {
		return null;
	}
	public static void main(String... args) {
		Object b=B.create();
	}
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
- do not hide static methods with different type parameter specifications. (Use other method name)... But this makes my code more difficult to use because a more complex coding pattern must be followed. :(

Comments
EVALUATION This is not a bug. The methods are different and B.create does not hide A.create.
18-05-2007