Skip to content
Preptima
mediumConceptCodingMidSeniorStaff

What does the compiler erase from a generic type, and how do you decide between ? extends and ? super?

Generic type arguments exist only for the compiler; the bytecode keeps a raw type plus a signature string, which is why there is no T.class and no new T[]. Wildcards then follow producer-extends, consumer-super: read through ? extends, write through ? super.

5 min readUpdated 2026-08-15

Answer

Short answer

Java type erasure means generic type arguments are checked by the compiler but mostly absent from runtime instances. Use ? extends when a parameter only produces values for you to read, and ? super when it consumes values you need to write, because the compiler can only prove one direction safely.

Was this answer helpful?

Likely follow-ups

  • Why does the compiler generate a bridge method when you implement Comparable<Foo>?
  • What does @SafeVarargs assert, and when would applying it be a lie?
  • How does Jackson recover the element type of a List<Order> if erasure removed it?
  • Why can you not overload a method on List<String> and List<Integer>?

Related questions

Further reading

Related Topics