uima-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jörn Kottmann <kottm...@gmail.com>
Subject Re: generics: getViewIterator
Date Sun, 09 Aug 2009 20:17:49 GMT

On Aug 8, 2009, at 10:57 PM, Marshall Schor wrote:

> Jörn Kottmann wrote:
>>
>> On Aug 7, 2009, at 8:57 PM, Marshall Schor wrote:
>>
>>> getViewIterator in CASImpl is written with the signature:
>>> Iterator<CAS> getViewIterator()
>>>
>>> If you are working with things needing CASImpl objects, you would  
>>> write:
>>>
>>> Iterator<CAS> s = aCas.getViewIterator();
>>> while (s.hasNext()) {
>>>   CASImpl ci = (CASImpl) s.next();
>>>     ... code using ci...
>>> }
>>>
>>> If we changed the signature to:
>>> Iterator<T extends CAS> getViewIterator()
>>> then you would write:
>>> Iterator<CASImpl> s = aCas.getViewIterator(); // cast done inside  
>>> the
>>> support code, not here
>>> while (s.hasNext()) {
>>>   CASImpl ci = s.next();  // works OK without casting
>>>     ... code using ci...
>>> }
>>>
>>> Would it be better to have that form of the signature?
>>
>> +1, though did not know that its possible, we should check other
>> places too
>
> +1 to checking other places :-)
>
> The tutorial on generics by Gilad Bracha,
> http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf,  on page 20  
> near
> the top says:
>
>> In general, if you have an API that only uses a type parameter T as  
>> an
>> argument, its
>> uses should take advantage of lower bounded wildcards (? super T).
>> Conversely, if
>> the API only returns T, you’ll give your clients more flexibility by
>> using upper bounded
>> wildcards (? extends T).
>
> There are many cases I think in our generification where the 2nd  
> part of
> this, returning XXX<? extends T> or a variant, is a better choice.

In the end we can do this generification for all methods which
return an object of a type which is declared by an UIMA interface,  
right ?

Jörn
Mime
View raw message