Wildcards

If needed a wildcard generic type, which accepts any type, can be used:

public void function(List<?> list);
function(new ArrayList<String>());

function(new ArrayList<Double>());

Bounds

This is an upper bounds wildcard:

List<? extends Number> list;

Which accepts Number and it subclasses.

This is an lower bounds wildcard:

List<? super Number> list;

Which accepts Number and it super-classes.

Last updated