I know that there was a similar question already posted, although I think mine is somewhat different...
Suppose you have two methods:
// Bounded type
There are following three types of Wildcard usually used with Generic in JAVA. Each one is explained as below with example.
Upper-bounded Wildcard:
? extends T : In Upper bounded wildcard only T or its subtypes will be supported.
For example we have an Animal class and have Dog , Cat as its subtypes. So following generic methods will only
accept parameters of type Data
public static void add(Data extends Animal> animalData) {
}
Lower-bounded Wildcard:
? super T : In Lower-bounded wildcard only T or its super types will be supported. Same example we used for defining Lower-bounded Wildcard. Lets say we have Animal class as super or parent class and Dog as its child class. Now below method use Lower-bounded Wildcard and will only accept parameters of type
Data, Data and Data
Unbounded Wildcard:
? : Unbounded wildcard supports all types. So our above example method can take parameters of type
Data, Data , Data