method ()" Sometimes this (relatively strange looking) syntax is required to avoid type mi...">

What is the generic syntax name in: "X. <String, String> method ()"

Sometimes this (relatively strange looking) syntax is required to avoid type mismatch. But what is the name of this syntax really?

An example of using Google Guava (r07):

ImmutableMap defines a method

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

It can be used as follows:

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

This, by the way, is the built-in version:

 Builder<String, String> builder = ImmutableMap.builder(); ImmutableMap<String, String> map = builder.put("a", "A").build(); 
+4
source share
2 answers

I do not think the syntax has a specific name. I reviewed JLS, and it just mentions it as a β€œ generic method call”.

In your case, you can narrow it down to "calling a non-static general method."

If you refer to the fact that type parameters are present on the call side, you simply say "calling a generic method with explicit type parameters ".

To give an example where it (sort) is specified in JLS

When deciding whether a method is applicable, in the case of general methods (Β§8.4.4), it is necessary to determine the actual type arguments. Actual type arguments can be passed explicitly or implicitly. If they are passed implicitly, they must be inferred (Β§15.12.2.2.7) from the types of the expression of the arguments.

+6
source

if the syntax you are talking about is angular brackets, then they are called TYPE OPTIONS.

+3
source

All Articles