class Thing<T> {
public Map<String, List<String>> getData() { ... }
}
class Thingamajig {
void doStuff() {
Thing myThing = ...;
List<String> data = myThing.getData().get("some_key");
}
}
The call to myThing.getData()
gives the following error:
incompatible types: java.lang.Object cannot be converted to java.util.List
This is fixed by giving generic arguments to the Thing
instance:
void doStuff() {
Thing<?> myThing = ...;
List<String> data = myThing.getData().get("some_key");
}
Even a generic wildcard fixes the issue. To me, this makes no sense as getData()
is not even referencing the generic type argument.