Why does Java allow calling methods with type arguments that have no type parameters?
I recently learned that you can call a method that has no type parameter with arbitrary type arguments. Consider the following code:
public class Test {
public static void main(String[] args) {
Test.foo(); // d'uh
Test.<Integer>foo(); // yep
Test.<String, Integer, Float>foo(); // yep!
}
static void foo() { }
}
Now there are many things that are technically allowed by the grammar, but create compiler errors. Why is it slipping?
Also interesting: calling a method like this generates an alert in Eclipse, but javac
doesn't say anyting even with -Xlint
.
+3
source to share
No one has answered this question yet
See similar questions:
or similar: