Marshall Schor wrote:
A user had written this:
public static <T extends Annotation> Iterator<T> annotationsIterator(
JCas aJCas, int type) {
return aJCas.getAnnotationIndex(type).iterator(); // fails, cannot
convert from FSIterator<AnnotationFS> to Iterator<T>
}
This compile-time error can be eliminated by changing the generification
of AnnotationIndex as follows:
Currently AnnotationIndex is defined:
public interface AnnotationIndex extends FSIndex<AnnotationFS>
If the definition is changed to:
public interface AnnotationIndex <T extends AnnotationBaseFS> extends
FSIndex<T>
then the user's code above no longer gives a compile-time error. (It
does give a warning though - an unchecked conversion is needed).
This change makes AnnotationIndex, itself, a generic type, with a type
parameter indicating the type the index is over.
Is this a correct improvement?
In my opinion it must be
public interface AnnotationIndex <T extends AnnotationFS> extends
FSIndex<T>
because the AnnotationIndex interface promises to only contain
uima.tcas.Annotations and if T extends AnnotationBaseFS it could
be somthing else, right ?
Jörn