Commit 8e01b62
committed
docs(generics): explain upper-bounded wildcards (? extends T) in Java
WHAT:
- Added detailed documentation explaining the concept of **upper-bounded wildcards** in Java Generics.
- Clarified syntax, purpose, and real-world usage scenarios.
DETAILS:
- Syntax: `<? extends SomeClass>` → type can be `SomeClass` or any subclass.
- Example context: `List<? extends Number>` allows `Integer`, `Double`, `Float`, etc.
- Focused on the *read-only* nature of collections with `? extends T`
(safe for reading, not for adding new elements).
- Explained how this pattern represents **covariance** in Java Generics.
WHY:
- Prevents code duplication by allowing methods to handle collections of multiple subtypes.
- Ensures type safety when processing hierarchies (e.g., `Number` and its subclasses).
- Ideal when you need to **consume** or **process** data but not **insert** into the collection.
REAL-WORLD USE:
- Processing lists of numeric values (e.g., `List<Integer>`, `List<Double>`) with a single utility method.
- Useful in mathematical libraries, data aggregation, and reporting systems where inputs
may vary but are all subtypes of a common parent class.
Signed-off-by: https://github.com/Someshdiwan <[email protected]>1 parent fee6c53 commit 8e01b62
File tree
1 file changed
+20
-0
lines changed- Section24JavaGenerics/src/UpperBoundedWildcards
1 file changed
+20
-0
lines changedLines changed: 20 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
0 commit comments