EVALUATION
The exact specification is found in
JLS3 15.12.2.1 Identify Potentially Applicable Methods
"If the method invocation includes explicit type parameters, and
the member is a generic method, then the number of actual type
parameters is equal to the number of formal type parameters."
This says nothing about explicit parameters to non-generic methods
implying that these are ignored.
http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.12.2.1
However, there are various degrees of ignoring. Should this program
compile:
class Test {
static void m() {}
public static void main(String... args) {
Test.<Can,I,write,a,little,story,here>m();
}
}
Currently, it doesn't and that is reasonable if we assume that the
explicit type arguments are categorized as type names, according
to JLS3 6.5.5.1 Simple Type Names:
"If a type name consists of a single Identifier, then the identifier
must occur in the scope of exactly one visible declaration of a type
with this name, or a compile-time error occurs. The meaning of the
type name is that type."
|
SUGGESTED FIX
Index: j2se/src/share/classes/com/sun/tools/javac/comp/Resolve.java
--- /tmp/geta18390 2006-11-01 18:30:53.000000000 -0800
+++ /tmp/getb18390 2006-11-01 18:30:53.000000000 -0800
@@ -275,7 +275,7 @@
if (typeargtypes == null) typeargtypes = List.nil();
if (mt.tag != FORALL && typeargtypes.nonEmpty()) {
// This is not a polymorphic method, but typeargs are supplied
- return null;
+ // which is fine, see JLS3 15.12.2.1
} else if (mt.tag == FORALL && typeargtypes.nonEmpty()) {
ForAll pmt = (ForAll) mt;
if (typeargtypes.length() != pmt.tvars.length())
|
EVALUATION
This test appears to be wrong. No type arguments are given to methods without type parameters (both callA and callB are generic and takes one type argument).
Also the current specification allows one to pass any number of type arguments to a method which does not take one. Currently, the compiler cannot handle this, so I'll leave this bug open.
###@###.### 2004-08-03
|