dimanche 25 novembre 2018

How do i get type of Foo

This question already has an answer here:

No! I dont want to get type of T. I want to get type of Foo<T>. the following gives error

KeyValueItem<TKey, TValue>.class

but I have a generic array, and i have to initialize it like this

T[] newArr = (T[]) Array.newInstance(clazz, cap);

where T will be KeyValueItem<TKey, TValue> in this case.

I am fine if its required to have TKey.class and TValue.class and somehow build a new type from it. I just dont know how to do it.

These kind of things were piece of cake in C#, but its real pain in java. java is terrible at generics.





Aucun commentaire:

Enregistrer un commentaire