[ 
https://issues.apache.org/jira/browse/UIMA-5115?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15520448#comment-15520448
 ] 

Richard Eckart de Castilho commented on UIMA-5115:
--------------------------------------------------

Ok, so here is my argument...

If we infer the return type by the variable to which it is bound, we can 
happily do this:

{code}
SelectFSs<Token> selector = jcas.select().type("my.Token");
{code}

But we cannot do these:

{code}
1 | List<AnnotationFS> selector = jcas.select().type("my.Token").asList()
2 | doSomethingWith(jcas.select().type("my.Token"));
{code}

In case 1, we would have to introduce an additional signature of asList() which 
would interfere with the normal typesafe one (i.e. once returning the generic 
type of SelectFSs and once obtaining the generic type from the variable to 
which the result is assigned). So the List cannot have the generic type 
AnnotationFS, but would need to use FeatureStructure or would require casting.

In case 2, Java is not smart enough to infer the generic type from the argument 
of "doSomethingWith" and we would have to resort to type casting. So 
doSomethingWith could not accept an AnnotationFS  but would have to be able to 
operate on a FeatureStructure.

{code}
1 | List<AnnotationFS> selector = (List<AnnotationFS) (List) 
jcas.select().type("my.Token").asList()
2 | doSomethingWith((List<AnnotationFS) (List) jcas.select().type("my.Token"));
{code}

With the following signatures, that ugly casting problem is resolved:

{code}
1 | List<AnnotationFS> selector = jcas.select().type("my.Token", 
AnnotationFS.class).asList()
2 | doSomethingWith(jcas.select().type("my.Token", AnnotationFS.class));
{code}



> uv3 select() api for iterators and streams over CAS contents
> ------------------------------------------------------------
>
>                 Key: UIMA-5115
>                 URL: https://issues.apache.org/jira/browse/UIMA-5115
>             Project: UIMA
>          Issue Type: New Feature
>          Components: Core Java Framework
>            Reporter: Marshall Schor
>            Priority: Minor
>             Fix For: 3.0.0SDKexp
>
>
> Design and implement a select() API based on uimaFIT's select, integrated 
> well with Java 8 concepts.  Initial discussions in UIMA-1524.  Wiki with 
> diagram: https://cwiki.apache.org/confluence/display/UIMA/UV3+Iterator+support



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to