I have the following code:
Collection<Something<ConcreteA, ConcreteB>> methodOne() {
....
}
void methodTwo(Collection<Something<ConcreteA, ?>> val) {
....
}
// This call generates an error.
methodTwo(methodOne());
The methodTwo(methodOne()) generates an error: incompatible types: Collection<Something<ConcreteA,ConcreteB>> cannot be converted to Collection<Something<ConcreteA,?>>.
I understand that I can just cast methodTwo((Collection) methodOne()) and everything works fine except for the Unchecked assignment warning which can be ignored. But that defeats the purpose of using generics. Changing methodTwo signature from capture to Object also does not help, i.e. methodTwo(Collection<Something<ConcreteA, Object>> val) also produces a similar error.
What am I doing wrong? What is the right way of dealing with it?