I'm trying to use a wildcard type in a method signature and pass different parameterized types. It works fine if it's only a GenericItemWrapper, but it fails if that GenericItemWrapper is a type parameter itself. Here's what eclipse complains about:
The method DoStuff(Map<String, Test.GenericItemWrapper<?>>) in the type Test
is not applicable for the arguments (Map<String, Test.GenericItemWrapper<String>>)
Here's the code:
import java.util.Map;
public class Test
{
public static void main(String[] args)
{
Map<String, GenericItemWrapper<Long>> longWrapper = null;
Map<String, GenericItemWrapper<String>> stringWrapper = null;
Test t = new Test();
t.DoStuff(longWrapper); // error here
t.DoStuff(stringWrapper); // error here
}
public void DoStuff(Map<String, GenericItemWrapper<?>> aParam)
{
;
}
public static class GenericItemWrapper<ItemType>
{
private ItemType mItem;
public GenericItemWrapper(ItemType aItem)
{
mItem = aItem;
}
}
}