mardi 12 mars 2019

Java String to generics type

I have a class defined like this

class MyTransformer<V, M extends SomeBaseM> extends Transformer<V,M> {
  ...
}

In all cases but one I would instantiate it like this

MyTransformer<Foo,Bar> t = new MyTransformer(...);

There is this one case where I get the generic types as a Class instead:

void annoyingCaller( Class<? extends V> vClass, Class<? extends SomeBaseM> M, ... ) {
  MyTransformer<?,?> t = new MyTransformer(...);
}

Is there anything I can do to populate these generic type (via reflection perhaps?)





Aucun commentaire:

Enregistrer un commentaire