[infinispan-issues] [JBoss JIRA] (ISPN-2826) CacheQuery.list() returns List<Object>, which is hard to cast

Sanne Grinovero (JIRA) jira-events at lists.jboss.org
Fri Feb 15 16:05:56 EST 2013


    [ https://issues.jboss.org/browse/ISPN-2826?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12754565#comment-12754565 ] 

Sanne Grinovero edited comment on ISPN-2826 at 2/15/13 4:05 PM:
----------------------------------------------------------------

Hi Ray, thanks for the idea, but without large changes in functionality that can't be fixed: technically your query could target multiple types which have no types in common:

{code}
CacheQuery query = searchManager.getQuery(luceneQuery, Book.class, Airplane.class, User.class);
{code}

So even if we used extended generics all over, there would be mixed results. Also, one can not infer the type from the original Cache<?,?> generic values as, even when knowing it's a Cache<String,Book> one might want to use projections to extract the titles in one-shot.

I agree we should improve the API, but we'd likely need additional methods.
                
      was (Author: sannegrinovero):
    Hi Ray, thanks for the idea, but without large changes in functionality that can't be fixed: technically your query could target multiple types which have no types in common:

{code}
CacheQuery query = searchManager.getQuery(luceneQuery, Book.class, Airplanes.class, Users.class);
{code}

So even if we used extended generics all over, there would be mixed results. Also, one can not infer the type from the original Cache<?,?> generic values as, even when knowing it's a Cache<String,Book> one might want to use projections to extract the titles in one-shot.

I agree we should improve the API, but we'd likely need additional methods.
                  
> CacheQuery.list() returns List<Object>, which is hard to cast
> -------------------------------------------------------------
>
>                 Key: ISPN-2826
>                 URL: https://issues.jboss.org/browse/ISPN-2826
>             Project: Infinispan
>          Issue Type: Feature Request
>          Components: Querying
>            Reporter: Ray Tsang
>            Assignee: Sanne Grinovero
>
> In example for Books in https://docs.jboss.org/author/display/ISPN/Querying+Infinispan
> ~~ snip snip ~~
> CacheQuery query = searchManager.getQuery(luceneQuery, Book.class); 
> // and there are your results!
> List<Book> objectList = query.list();
> ~~ snip snip ~~
> This doesn't actually work.  CacheQuery.list() returns List<Object>
> Thus, you will need to cast: List<Book> books = (List<Book>) cq.list();
> But this wouldn't work... Instead you'll end up doing: List<Book> books = (List<Book>)(List<?>) cq.list();

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the infinispan-issues mailing list