Search code examples
javagenericsbounded-wildcard

Use of "super" with "?" in Java


I am trying to read and understand some Java code. Here it is:

protected LoadTarget<? super PopulationLoadContext> createTarget(PopulationLoadContext context) {
    return createTransactionalTargetGroup(RiskScoresTables.All_Tables);
}

What does the <? super PopulationLoadContext> mean?


Solution

  • In Java, that is a lower-bounded wildcard in generics, which stands for PopulationLoadContext or any superclass of that class.

    It could be a LoadTarget<PopulationLoadContext>, or it could be a LoadTarget<Object>, or anything in between (if in between classes exist).