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.

[980 byte] By [IgorGT31415926a] at [2007-11-26 18:10:21]
# 1
are you asking if you can check at runtime whether your generics declarations are being satisfied? likeisAssigableFrom(Set<Integer>.class);can't be done. generics don't exist at runtime
georgemca at 2007-7-9 5:42:39 > top of Java-index,Java Essentials,Java Programming...
# 2

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).

IgorGT31415926a at 2007-7-9 5:42:39 > top of Java-index,Java Essentials,Java Programming...
# 3
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
georgemca at 2007-7-9 5:42:39 > top of Java-index,Java Essentials,Java Programming...
# 4
My question is:where is Type.isAssignableFrom( Type ) method? :)
IgorGT31415926a at 2007-7-9 5:42:39 > top of Java-index,Java Essentials,Java Programming...
# 5
don't think there is such a thing. what do you need beyond what Class.isAssignableFrom gives?
georgemca at 2007-7-9 5:42:39 > top of Java-index,Java Essentials,Java Programming...
# 6

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.

IgorGT31415926a at 2007-7-9 5:42:39 > top of Java-index,Java Essentials,Java Programming...