Lets research some generic instantion situation using wild card:
1
This code
List<?> list = new ArrayList<?>();
generates following error:
required: class or interface without bounds
found: ?
2
But this
List<?> list = new ArrayList< Set<?> >();
compiles succesfully.
3
and this:
List<Set<?>> list = new ArrayList< Set<?> >();
compiles succesfully too.
4
but this:
List<Set<Map<?,?>>> list = new ArrayList< Set<Map<String,String>> >();
generates
required: List<Set<Map<?,?>>>
found: ArrayList<Set<Map<String,String>>>
5
List<Set<?>> list = new ArrayList< HashSet<?> >();
generates
required: List<Set<?>>
found: ArrayList<HashSet<?>>
I am very confusing about these outputs.
I see following regularity:
I can replace ?
from left part on right part only on first level and types should be same inside <> and just ? and ? is forbid.
But I don't understand why?
Can you provide common rules how to instantiate generics using wild card?