mardi 21 mai 2019

Convert Class name to generic type [duplicate]

This question already has an answer here:

Instead of having the type, I have the className, and what I need is to use this class name in a generic class.

As maybe this could be confusing I will put a simple example.

To create a List of Integer we put:

List<Integer>

Now imagine that, instead of Integer we have an string with the following value: "java.lang.Integer".

How I could convert this string intro the Integer type.

I have tried lots of thinks but thew one that makes more sense and that doesn't work is the following:

List<Class.forName("java.lang.Integer")>

Maybe this question is repeated but i didn't find it in anywhere.





Aucun commentaire:

Enregistrer un commentaire