[infinispan-dev] Generics usage in org.infinispan.util.ClassFinder

Emmanuel Bernard emmanuel at hibernate.org
Wed Oct 7 07:36:06 EDT 2009


On 7 oct. 09, at 12:21, Galder Zamarreno wrote:

>
>
> On 10/07/2009 12:11 PM, Emmanuel Bernard wrote:
>> Class<?>  is the closest equivalent to Class. It adds no burden at  
>> all
>> (people can still use the raw type if they wish to stay in the pre-5
>> era). And literally Class<?>  means what you've described: "we can't
>> say anything about the Class type returned"
>
> I think it's a burden cos you're forcing client to either accept
> Class<?> or cast to Class. Example:
>
> A method defined as:
>
> public static List<Class<?>> infinispanClasses();
>
> Any client needs to do:
>
> List<Class<?>> ispnClasses = ClassFinder.infinispanClasses(cp);
>
> A client can't do:
>
> List<Class> ispnClasses = ClassFinder.infinispanClasses(cp);
>
> I see that as a burden on the client cos you're forcing the client to
> deal with generics that say nothing.

Ah so you like generics and their type-safety and you don't in the  
same declaration :)
Generally speaking Type and Type<?> are different. Type is more  
equivalent to Type<? extends Object> I think. This is particularly  
true of collections where you cannot add anything but null in a  
Collection<?> while you can add anything in Collection. In the case of  
Class<T>, there is no consumer method taking T, so the difference is  
not visible AFAIK.

That being said, List<Class> is a PITA for people using generics  
property as you can't cast to List<Class<?>>. You basically have to  
copy the list over.




More information about the infinispan-dev mailing list