[jboss-dev] generic collection item type

Adrian abrock at redhat.com
Mon Jul 30 06:57:18 EDT 2007


On Mon, 2007-07-30 at 10:35 +0200, Alexey Loubyansky wrote:
> 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.
> 

Well that's a more complicated use case. 
I don't see why you can't make it work. 
You've just got to locate where it the type hierarchy
and what paremeter the collection is.

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

Perhaps we can add that to the ClassInfo model?

if (classInfo.isCollection())
   typeInfo = classInfo.getComponentType();

and it would do all the hard work of locating the collection
definition and retrieving the type.

We could also do something similar for maps, i.e.

if (classInfo.isMap())
{
   keyType = classInfo.getKeyType();
   valueType = classInfo.getValueType();
}
-- 
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Adrian Brock
Chief Scientist
JBoss, a division of Red Hat
xxxxxxxxxxxxxxxxxxxxxxxxxxxx




More information about the jboss-development mailing list