This content has been marked as final. Show 6 replies
The Future object is returned by the Submit method which is used to retrieve the Callable return value. But you are saying that Future is a generic type. I am not finding much that clears this up for me.
The line above creates a HashSet of the type "Future<Integer>>" whic you say is a generic type. What role does <Integer> play? Sorry for all the questions.
To quote from the API documentation for Future:
V - The result type returned by this Future's get methodYou don't need to apologize for all the questions, but you might find it more practical to read the API documentation before asking them. This one at least could have been answered in under a minute that way.
user606303 wrote:Right, because the List type takes a single type Parameter for its element type. And you can do
I can define a collection like this:
1) List<String> list = new ArrayList<String>();
because the Map type takes two type parameters, for its key type and its value type.
Map<String, Integer> map = new Hashmap<String, Integer>();
And other classes besides collections have type parameters that they use for their own purposes.
And if, for instance, you have a List of Maps, you might do
But since Map also takes type parameters, you'd probably specify those too:
List<Map> list = new ArrayList<Map>();
List<Map<String, Integer>> list = new ArrayList<Map<String, Integer>>();
The parts of that line are:When Type itself has no type parameters of its own, yes. But if Type is itself parameterized, then you get something like the most recent example above.
2) Interface<Type> CollectionName = new Implementation<Type>
I am seeing the following with no explanation about what is going on:In this case, Type is Future, and Future itself takes a type parameter. As DrClap pointed out, the meaning of that particular type parameter for that particular class can be found in Future's docs, but, structurally, since a type can be parameterized by another type, as List is parmaeterized by <String> in your first example, the type parameter can itself be parameterized, theoretically to infinite depth, but I think the language puts a limit of 256 levels or something like that.
3) Set<Future<Integer>> set = new HashSet<Future<Integer>>()