Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Proper Generic Syntax for a Nested Collection of Objects on a method Parameter

 
author and cow tipper
Posts: 5000
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a method defined in an Interface that returns a Question:



The pseudo implementation uses generics to indicate the AsyncCallbak will return a Question:

public void saveQuestion(Question question, AsyncCallback<Question> callback);

I have another method that returns a List of Question objects:



How do I indicate that the AsynchCallback is returning a List of Questions, List<Question>.

The following will fail, because I have only genericized the List, not the List<Question>.

public void getAllQuestions(AsyncCallback<List> callback);

Essentially, I have a container containing a container containing a container. So, I need to genericize 'two deep.'

I don't want to just use <List>, but I want to indicate that it's a List<Question>. What's the syntax?


 
Cameron Wallace McKenzie
author and cow tipper
Posts: 5000
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sitting here, talking it out, I decided to try something:



Man, that syntax looks awful. No possible way that should work, right?

Go figure?

-Cameron McKenzie
 
Marshal
Posts: 25818
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean this?

 
Cameron Wallace McKenzie
author and cow tipper
Posts: 5000
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul. I knew I'd have an answer before I had time to get a pop from the fridge.

Back to work...
    Bookmark Topic Watch Topic
  • New Topic