I'm new to Java programming. While reading through the code of an open source project, I came across a line of code which I can't understand:
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
My questions are:
- I usually call a constructor like this:
final Type typeOfMap = new TypeToken<Map<String, Object>>()
. I have never seen it followed by other pieces of code such as{}.getType()
. What kind of syntax is this? - Is
{}
an object? Why can you call a function on it?
P.S. Type
is java.lang.reflect.Type
, and TypeToken
is com.google.gson.reflect.TypeToken
.
Aucun commentaire:
Enregistrer un commentaire