Java Zero to All All questionsPractise free
Interview questions › Java Foundations — Zero to Basics › Generics — Wildcards, Bounded Types, PECS

What is a recursive generic bound like <T extends Comparable<T>>, and where does it show up?

Level III · MidGenerics — Wildcards, Bounded Types, PECS
Short answer

It's a self-referential bound expressing 'T must be comparable to its own type', which is how Collections.max and sorting APIs guarantee elements can be ordered against each other rather than against arbitrary objects.

Explanation

The same pattern powers the self-typed builder idiom (<T extends Builder<T>>) so fluent methods return the concrete subtype. It looks circular but is a standard way to make generic APIs both type-safe and ergonomic; the cost is the declaration gets verbose and intimidating to readers.

Common mistakes
  • Not recognising this pattern in Comparable, Enum<E> and builders.
  • Writing <T extends Comparable> with the raw type.

Can you say this out loud in two minutes? Drill it in a timed mock interview, with flashcards and runnable code for Generics — Wildcards, Bounded Types, PECS.

Practise free

More on Generics — Wildcards, Bounded Types, PECS