JavaIntermediate#generics

What is a bounded type parameter in generics?

A generic type parameter constrained to extend a specific class or implement an interface, restricting which types can be used and enabling calling methods of that bound within the generic code.

Example
static <T extends Comparable<T>> T max(T a, T b) {
  return a.compareTo(b) > 0 ? a : b;
}
max(3, 5); // 5

Related Questions

1
JavaBeginner#generics

Can you use primitive types with generics?

Open
2
JavaAdvanced#generics

What is type erasure in Java generics?

Open
3
JavaIntermediate#collections

How do you sort a List of custom objects by multiple fields?

Open