A lower bounded wildcard in Java restricts an unknown generic type to be a specific class or any of its superclasses. Denoted by theDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
<? super T> syntax, it establishes a lower limit on the type hierarchy, meaning the parameterized type must be T or an ancestor of T (up to java.lang.Object).
Syntax
The wildcard is declared using the? character, followed by the super keyword, and then the lower bound type.
Assignment Compatibility
When a reference is declared with a lower bounded wildcard, it can point to a generic object parameterized with the exact type or any of its supertypes. For example, aList<? super Number> can accept:
List<Number>List<Object>
List<Integer> or List<String>, resulting in a compile-time error, because neither Integer nor String are superclasses of Number.
Read and Write Mechanics
The primary technical implication of a lower bounded wildcard dictates how the compiler handles reading from and writing to the generic structure.Writing (Insertion)
You can safely add instances of the lower bound typeT, or any of its subclasses, into the structure. The compiler allows this because a collection designed to hold T or any superclass of T is inherently capable of holding a T (and by extension, any valid subclass of T).
Reading (Retrieval)
Reading from a lower bounded wildcard is highly restricted. Because the compiler only knows that the collection holds some supertype ofT, it cannot guarantee the specific type of the elements being retrieved. The only safe assumption the compiler can make is that the elements are instances of java.lang.Object.
Code Visualization
Type System Role
In Java’s generic type system, lower bounded wildcards implement contravariance. They invert the standard subtyping relationship, allowing a generic type to accept a wider, more generic type argument. This mechanic enforces type safety for operations that mutate (consume) data, ensuring that heap pollution does not occur when passing generic collections across different API boundaries.Master Java with Deep Grasping Methodology!Learn More





