uima-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thilo Goetz <twgo...@gmx.de>
Subject Re: generics: AnnotationIndex.subiterator
Date Tue, 25 Aug 2009 12:52:31 GMT
Jörn Kottmann wrote:
> Jörn Kottmann wrote:
>> FSIterator<T> subiterator(AnnotationFS annot);
>>
>> Is that correct ?
>>
>> It leads to a problem in the Subiterator class, because it calls
>> moveTo(annot) on an FSIterator, but  annot must not have type
>> T.
> The AnnotationIndexImpl has this method
> 
>  public FSIterator<AnnotationFS> subiterator(AnnotationFS annot, boolean
> ambiguous, boolean strict) {
>    return new Subiterator<AnnotationFS>(this.index.iterator(), annot,
> ambiguous, strict);
>  }
> 
> if now the AnnotationFS is replaced by a T which is defined as T extends
> AnnotationFS then,
> the method is changed to
>  public FSIterator<T> subiterator(AnnotationFS annot, boolean ambiguous,
> boolean strict) {
>    return new Subiterator<T>(this.index.iterator(), annot, ambiguous,
> strict);
>  }
> which leads to a compile error because Subiterator expects annot to be
> of type T and not of
> type AnnotationFS. Subitertor calls on the passed iterator moveTo(annot)
> which creates a
> conflict here.
> 
> Jörn

I see.  The subiterator generification is wrong.  In the
constructor, it shouldn't be

  Subiterator(FSIterator<T> it, T annot, final boolean ambiguous, final boolean
strict) {

but instead

  Subiterator(FSIterator<T> it, AnnotationFS annot, final boolean ambiguous,
final boolean strict) {

because the annotation that defines the range of the subiterator
does not have to be (and usually is not) of the same type as
the iterator.  Does that make sense?  This is like the case with
moveTo() that we discussed.

--Thilo

Mime
View raw message