Why does Java allow calling methods with type arguments that don't have type parameters?

66 views Asked by At

I recently found out 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 a lot of things that are technically allowed by the grammar but create compiler errors. Why did this slip through?

Also interesting: Calling a method like that creates a warning in Eclipse but javac doesn't say anyting, even with -Xlint.

0

There are 0 answers