aspose file tools
The moose likes Java in General and the fly likes Proper Generic Syntax for a Nested Collection of Objects on a method Parameter Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Proper Generic Syntax for a Nested Collection of Objects on a method Parameter" Watch "Proper Generic Syntax for a Nested Collection of Objects on a method Parameter" New topic
Author

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

Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4967

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
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4967

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
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16487
    
    2

You mean this?

Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4967

Thanks Paul. I knew I'd have an answer before I had time to get a pop from the fridge.

Back to work...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Proper Generic Syntax for a Nested Collection of Objects on a method Parameter
 
Similar Threads
Getting access to the DatabaseServerLoginModule
how to add an array to an ArrayList
RPC problems Method isPrimeNumber of 'PrimeNumber' is not synchronized with 'PrimeNumberAsync'
Calling multiple methods from RPC servlet
Passing a String[] to EntryPoint class sends a null object!