[jboss-dev] generic collection item type

Alexey Loubyansky alexey.loubyansky at redhat.com
Mon Jul 30 04:35:22 EDT 2007


This approach assumes that the component type can be determined with

TypeInfo[] types = typeInfo.getActualTypeArguments();
if (types != null)
    elementType = types[0];

This won't work for this class
https://svn.jboss.org/repos/common/jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/JBossEnterpriseBeansMetaData.java

for which its super class should be checked for type arguments and the 
component type is the second argument.

I guess I'll need to specify the component type with an annotation. But 
it would be nice to have something like Class.getComponentType() to work 
for generic collections too.

Alexey

Adrian wrote:
> Yes. Ales asked the same question a couple of months ago,
> but this example wasn't committed then.
> 
> See generateCollection() here:
> http://anonsvn.jboss.org/repos/jbossas/projects/microcontainer/trunk/metatype/src/main/org/jboss/metatype/plugins/types/DefaultMetaTypeFactory.java
> which defaults to java.lang.Object if it is not generic.
> 
> On Fri, 2007-07-27 at 12:52 +0200, Alexey Loubyansky wrote:
>> Is there a way to find out the item type of a generic collection at 
>> runtime using introspection or org.jboss.reflect?
>>
>> Thanks,
>> Alexey
>> _______________________________________________
>> jboss-development mailing list
>> jboss-development at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/jboss-development



More information about the jboss-development mailing list