[jboss-dev] generic collection item type

Alexey Loubyansky alexey.loubyansky at redhat.com
Mon Jul 30 05:03:23 EDT 2007


No, it won't.
This
       ClassInfo classInfo = (ClassInfo) 
configuration.getTypeInfo(JBossEnterpriseBeansMetaData.class);
       System.out.println("isCollection: " + classInfo.isCollection());
       System.out.println("type args: " + 
classInfo.getActualTypeArguments());
       System.out.println("superclass args: " + 
Arrays.asList(classInfo.getGenericSuperclass().getActualTypeArguments()));

results in

isCollection: true
type args: null
superclass args: 
[ReflectClassInfoImpl at f38798{name=org.jboss.ejb.metadata.spec.EnterpriseBeanMetaData}, 
ReflectClassInfoImpl at 4b222f{name=org.jboss.ejb.metadata.jboss.JBossEnterpriseBeanMetaData}, 
ReflectClassInfoImpl at b169f8{name=org.jboss.ejb.metadata.spec.EnterpriseBeansMetaData}]


Ales Justin wrote:
> This is not just Collection specific.
> 
> Doing this (TypeInfo[] types = typeInfo.getActualTypeArguments();) on 
> JBossEnterpriseBeansMetaData would return you those 3 types:
> 
> (pseudo code ;-)
> types[] = {EnterpriseBeanMetaData, JBossEnterpriseBeanMetaData, 
> EnterpriseBeansMetaData};
> 
> Rgds, Ales
> 
>  >>>
> 
> 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
> _______________________________________________
> 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