Interview replay

Full round replay — type erasure

10 minintermediate210 yrs

Timed verbal replay with pass/fail criteria per follow-up.

How to run this

Answer out loud, timed. Do not read the entry first. Then compare against "The Answer" and "Interviewer's Next Move" and mark yourself.

The opener

What is type erasure, and what does it prevent?

Budget: 45 seconds. Going long here is itself a fail signal.

Follow-ups

  1. 1. “Why can't you write new T[10]?

    Testing: Do they know arrays are reified and generics are not?

    Scoring

    Pass: Arrays carry their component type at runtime and check every store; T does not exist by then. Names the (T[]) new Object[] workaround and keeps it private.

    Fail: 'Java doesn't allow it' with no mechanism, or claims it is a syntax limitation.

  2. 2. “You said the type is erased. So how does Jackson build a List<Order>?

    Testing: The single best separator on this topic — erasure applies to instances, not declarations.

    Scoring

    Pass: Fields, parameters, return types and supertypes keep their generic type in the class file's Signature attribute. TypeReference is an anonymous subclass so there IS a declaration to read.

    Fail: 'Reflection' with no mechanism, or 'Jackson uses the runtime type of the object'.

  3. 3. “Why does new TypeReference<List<Order>>() need the empty braces?

    Testing: Do they understand what the braces create?

    Scoring

    Pass: They make an anonymous subclass; the subclass's generic superclass is List<Order> and getGenericSuperclass() reads it. Without them you have a variable, and a variable's type is not reachable at runtime.

    Fail: 'It's an abstract class' — true but not the reason — or 'it's just the API'.

  4. 4. “What does <T extends Comparable<T> & Serializable> erase to?

    Testing: Leftmost bound, and the binary-compatibility consequence.

    Scoring

    Pass: Comparable — the leftmost bound. Reordering the bounds changes every erased signature, so it is a binary-incompatible change.

    Fail: 'Object' or 'both'.

  5. 5. “A scanner walking getDeclaredMethods() reports your comparator twice. Why, and how do you fix it?

    Testing: Bridge methods — and whether they reach for the outdated annotation test.

    Scoring

    Pass: javac generated a bridge compare(Object) so the erased interface method is really overridden. Filter on Method.isBridge(). Notes that the bridge inherits the annotations, so filtering on those does not work.

    Fail: 'Filter the ones without the annotation' — which no longer works — or blames the framework.

  6. 6. “Someone adds @SuppressWarnings("unchecked") to the class to quiet the build. React.

    Testing: Judgement, not rules.

    Scoring

    Pass: Pushes back on blast radius: class level silences every future unchecked operation in the file. Suppress on the single statement with a comment saying why it is safe.

    Fail: Either 'fine, warnings are noise' or a blanket 'never suppress' with no reasoning.

Score yourself

6/6 — you can hold this topic at senior level 4-5 — solid; reread "Interviewer's Next Move" 0-3 — reread "Understand It" and redo the Challenge tier

← Back to What is type erasure, and what does it prevent?