jeudi 30 juillet 2020

Java how to get Class reference for a fuly parameterized GenericType

I'm trying to get a Class reference to a GenericType. Note that OtherType isn't just a place-holder - this is a fully parameterized type. And an example we could use List.

For a non-generic type I could do something like Class c = String.class

However if I try to do Class c = List<String>.class it doesn't compile....

How do I get a fully parameterized generic type Class reference?

EDIT: My goal is to use mokito to mock a TypedQuery for a unit test

Thank you





Aucun commentaire:

Enregistrer un commentaire