mercredi 12 février 2020

Handle Whole Type Name For Nested Classes

I use some nested classes like List, MyObject ...

Then I can find the type of them with using:

Type type = new com.google.gson.reflect.TypeToken<List<String>>() {}.getType();

But when I try to handle it with generic types like:

public static <T> T findClass(Class<T> resultClass)
    {
        //E.g. resultClass = String.class; Expect: List<String>
        Type type = new com.google.gson.reflect.TypeToken<List<T>>() {}.getType();
    }

It doesn't work for me.

In here, I wonder two things.

  1. Can I fix this problem?
  2. Can I describe a path like Class> in java?




Aucun commentaire:

Enregistrer un commentaire