An 'isAssignableFrom' question
Hello,
Sorry for my english.
I have 2 interfaces: Provider<T> and Consumer<T>.
There are implementations of these interfaces:
class PImplimplements Provider< Set<Integer> >{...}
class CImplimplements Consumer< Set< ?extends Number > >{...}
My program gets names of these classes, loads them (via ClassLoader) and wants to check that objects provided by the provider can be consumed by the consumer.
I can get provided and consumed classes as objects of java.lang.reflect.Type, but I have not found a method like isAssignableFrom for 'Type' objects. Does anybody know how this check can be done?
Thanks in advance.
I know that Set<Integer>.class
is illegal.
About 'generics don't exist at runtime' you are slightly wrong. There is some information about generics in runtime.
If Provider<T> is a class (not an interface) then (ParameterizedType)PImpl.getGenericSuperclass()
has a reference to the Provider.class (as getRawType()) and the list of actual generic arguments (in my case it is a one element list with Type(Set<Integer>) value).
what I mean is "the JVM makes no use of generics at runtime", yeh. there is some metadata present in the bytecodewell, what's your actual question, then? I couldn't quite work it out
I will try to explain my problem again.
I have a class that produces objects (for example Set<Integers>) and several classes that consumes objects. Each consumer implements Consumer<T> interface. I want to find all consumers that able to consume objects produced by the producer. My program gets names of these classes as parameters, so information about classes is not known at compile time.
This task is not too difficult if T is not a generic.