Skip to content
Preptima
mediumConceptMidSeniorStaff

Give me a subclass that the compiler accepts but that still breaks the Liskov substitution principle. What rule does it break?

5 min readUpdated 2026-08-15Target archetype: Big Tech, Enterprise Captive, Product Startup

Answer

Short answer

Substitutability is a claim about behaviour, and signatures carry none of it.A subclass that rejects an argument its supertype accepted has strengthened a precondition, which the compiler cannot see: the code type-checks, and it breaks callers that were written correctly against the base type.

Was this answer helpful?

Likely follow-ups

  • How do you choose between widening the supertype's contract and abandoning the inheritance relationship?
  • Why does adding a field and overriding equals break symmetry, and what are the two ways out of it?
  • Java's arrays are covariant. Where does that surface at runtime, and what did generics do differently?
  • What would a contract test suite for an interface with optional operations have to assert?

Related questions