Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this Java syntax, where it looks like the method is parameterized, mean?

Tags:

java

generics

Here is the code I'm looking at (using Google's ImmutableMap)

ImmutableMap.<String,String>of();

What does this mean? What is the significance of doing

Class.<GenericType>methodName()?
like image 369
Jeremy Avatar asked Feb 18 '23 23:02

Jeremy


1 Answers

ImmutableMap is a generic class with two type parameters, K and V. This syntax gives the concrete values for the two parameters, both being String in this case.

So the above returns an empty map of String to String.

See JLS 15.2 which among other things says a method invokation is

MethodInvocation:
     TypeName . NonWildTypeArguments Identifier ( ArgumentListopt )

Here the Type Arguments are String and String

like image 168
Miserable Variable Avatar answered Feb 21 '23 13:02

Miserable Variable