mardi 28 juillet 2015

What does it mean to resolve a type in Java?

What does it mean to resolve a type in Java?

Here are some usage examples with my attempts at making sense of them:

From Field#getGenericType():

If the type of the underlying field is a type variable or a parameterized type, it is created. Otherwise, it is resolved.

  • Type variables or parameterized types need to be created for this form of reflection to work because they can't be loaded, because they don't really "exist" at runtime?
  • So if something exists at runtime, it can be "resolved"? By the classloader?

From TypeToken#resolveType():

Resolves the given type against the type context represented by this type. For example:

new TypeToken<List<String>>() {}.resolveType(
    List.class.getMethod("get", int.class).getGenericReturnType())
=> String.class

  • This I don't really get at all. Not sure what this code is doing.




Aucun commentaire:

Enregistrer un commentaire