samedi 1 juin 2019

Reflection: Applying type parameters of declaring class to fields

I have the below class structure:

class A<T> {
   B<T> b;
}

class B<T> {
   T t;
}

class StringConsumer {
   A<String> a;
}

class LongConsumer {
   A<Long> a;
}

Given that I have an instance of one of the consumer classes, is it possible to obtain the type parameter for consumer.a.b? I found that I am able to resolve the same if I declare a as StringA a; where class StringA extends A<String> using TypeTools





Aucun commentaire:

Enregistrer un commentaire