I'd very much appreciate if somebody could provide a pointer on how to do the following.
I've defined a generic interface MyInterface<T> and several classes that implement this interface. I'd like to create an array the members of which can be assigned any object belonging to a class that implements the interface.
I know that an Object array would solve the problem of assigning objects from different classes. However, this is not very clean as I had lose type information and I had have to cast each time I get something from the array.
I've considered java.lang.reflect.Array.newInstance( Class C, int size ) but this requires a single class C and I'd end up with an array which only allows me assignments of C subclass objects.
Ideally, I'd like to declare the array as follows: MyInterface<Type>[] array, for a specific raw type.
Is there a way to do this?
Thanks in advance for your help.
Regards,
Bookmarks