Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the name of the generics syntax in: "X.<String, String>method()"

Sometimes this (relatively strange looking) syntax is required to avoid a type mismatch. But what's the name of that syntax actually?

Usage example from Google Guava (r07):

ImmutableMap defines a method

public static <K, V> Builder<K, V> builder()

It can be used like this:

ImmutableMap<String, String> map = 
        ImmutableMap.<String, String>builder().put("a", "A").build();

Which is by the way the inlined version of:

Builder<String, String> builder = ImmutableMap.builder();       
ImmutableMap<String, String> map = builder.put("a", "A").build();
like image 982
Chris Lercher Avatar asked Jan 22 '23 01:01

Chris Lercher


1 Answers

I don't think that syntax has a particular name. I've reviewed the JLS and it just mentions it as "a call to a generic method".

In your case one could narrow it down to "a call to a non-static generic method".

If you're referring to the fact that the type parameters are present on the call-side, you simply say "a call to a generic method with explicit type parameters".

To give an example where it is (sort of) mentioned in the JLS

Deciding whether a method is applicable will, in the case of generic methods (§8.4.4), require that actual type arguments be determined. Actual type arguments may be passed explicitly or implicitly. If they are passed implicitly, they must be inferred (§15.12.2.7) from the types of the argument expressions.

like image 53
aioobe Avatar answered Feb 17 '23 03:02

aioobe