You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@uima.apache.org by Marshall Schor <ms...@schor.com> on 2009/08/23 06:05:43 UTC
generics issue with iterators
After generification of iterators, this line in Lucas doesn't compile:
In src/main/java, org.apache.uima.lucas.indexer.analysis,
the class: AnnotationTokenStream
line 340:
annotationIterator =
Iterators.filter(jCas.getAnnotationIndex(annotationType).iterator(),
new NotNullPredicate<Annotation>());
gives message:
The method filter(Iterator<T>, Predicate<? super T>) in the type
Iterators is not applicable for the arguments (FSIterator<AnnotationFS>,
AnnotationTokenStream.NotNullPredicate<Annotation>)
I observe that if I change
new NotNullPredicate<Annotation>()); // to
new NotNullPredicate<AnnotationFS>());
that the error goes away, but is replaced with another error:
Type mismatch: cannot convert from Iterator<AnnotationFS> to
Iterator<Annotation>
I think the original form assigns to T the value AnnotationFS. This
makes the assignment of the predicate NotNullPredicate<X> have the type
X be a super type of AnnotationFS. But Annotation is a subtype, not a
supertype. So it fails.
I think the JCas version of
getAnnotationIndex(annotationType).iterator() should end up returning an
iterator over Annotation, not AnnotationFS. This would fix this, I think.
Opinions?
-Marshall
Re: generics issue with iterators
Posted by Adam Lally <al...@alum.rpi.edu>.
On Sun, Aug 23, 2009 at 12:05 AM, Marshall Schor<ms...@schor.com> wrote:
> After generification of iterators, this line in Lucas doesn't compile:
>
> In src/main/java, org.apache.uima.lucas.indexer.analysis,
> the class: AnnotationTokenStream
> line 340:
>
> annotationIterator =
> Iterators.filter(jCas.getAnnotationIndex(annotationType).iterator(),
> new NotNullPredicate<Annotation>());
>
> gives message:
>
> The method filter(Iterator<T>, Predicate<? super T>) in the type
> Iterators is not applicable for the arguments (FSIterator<AnnotationFS>,
> AnnotationTokenStream.NotNullPredicate<Annotation>)
>
>
> I observe that if I change
> new NotNullPredicate<Annotation>()); // to
> new NotNullPredicate<AnnotationFS>());
>
> that the error goes away, but is replaced with another error:
>
> Type mismatch: cannot convert from Iterator<AnnotationFS> to
> Iterator<Annotation>
>
> I think the original form assigns to T the value AnnotationFS. This
> makes the assignment of the predicate NotNullPredicate<X> have the type
> X be a super type of AnnotationFS. But Annotation is a subtype, not a
> supertype. So it fails.
>
> I think the JCas version of
> getAnnotationIndex(annotationType).iterator() should end up returning an
> iterator over Annotation, not AnnotationFS. This would fix this, I think.
>
> Opinions?
>
Makes sense to me.
-Adam
Re: generics issue with iterators
Posted by Jörn Kottmann <ko...@gmail.com>.
Marshall Schor wrote:
> After generification of iterators, this line in Lucas doesn't compile:
>
> In src/main/java, org.apache.uima.lucas.indexer.analysis,
> the class: AnnotationTokenStream
> line 340:
>
> annotationIterator =
> Iterators.filter(jCas.getAnnotationIndex(annotationType).iterator(),
> new NotNullPredicate<Annotation>());
>
> gives message:
>
> The method filter(Iterator<T>, Predicate<? super T>) in the type
> Iterators is not applicable for the arguments (FSIterator<AnnotationFS>,
> AnnotationTokenStream.NotNullPredicate<Annotation>)
>
>
> I observe that if I change
> new NotNullPredicate<Annotation>()); // to
> new NotNullPredicate<AnnotationFS>());
>
> that the error goes away, but is replaced with another error:
>
> Type mismatch: cannot convert from Iterator<AnnotationFS> to
> Iterator<Annotation>
>
> I think the original form assigns to T the value AnnotationFS. This
> makes the assignment of the predicate NotNullPredicate<X> have the type
> X be a super type of AnnotationFS. But Annotation is a subtype, not a
> supertype. So it fails.
>
> I think the JCas version of
> getAnnotationIndex(annotationType).iterator() should end up returning an
> iterator over Annotation, not AnnotationFS. This would fix this, I think.
>
But that would mean that we return an AnnotationIndex<Annotation>
and not AnnotationIndex<AnnotationFS>, right ?
Jörn