Generic Method with Lower Bound

Java-Generic Method with Lower Bound

Generic Method with Lower Bound Lower bounds are useful for cases where we want to be sure that a particular container instantiation can hold a particular element type, without limiting it to just the specific type of the element. For example, consider the following generic method: Note that T extends Comparable<T>. The Comparable is an generic interface declared … Read more…

Lower Bounds

Java-Lower Bounds

Lower Bounds Wildcard instantiations actually allow another type of bound called a lower bound as well. A lower bound is specified with the keyword super and requires that instantiations be of a certain type or any of its supertypes, up to upper bound of Type variable or Object. Consider the following classes and statement : The … Read more…

Bounded Wildcards

Java-Bounded Wildcards

Bounded Wildcards A bounded wildcard is a wildcard that uses the extends keyword just as a type variable would to limit the range of assignable types. For example : Our ‘abc’ variable is limited to holding instantiations of Gen on parameter types of A and its subclasses(B and C). So, we can assign it a Gen<A> or … Read more…