Java Design By Contract

Contracts as the semantics of a Java API, without a contract framework: preconditions, postconditions and invariants defined precisely and mapped to Java 25 mechanisms — constructor and compact-constructor validation, invariants as types that cannot represent invalid states, postconditions via tests and proportionate runtime checks, contracts documented in Javadoc, behavioural subtyping (overrides may weaken preconditions and strengthen postconditions, never the reverse), and contracts across sealed hierarchies. Use when a class's invariants live in its callers' heads, when an override adds a requirement its supertype never made, when deciding what @throws to promise, or when assert is guarding public input. Does not cover where boundary validation belongs (java-defensive-programming) or LSP in its five-principle context (java-solid).

robsonkades 8a86a93 4 files · 25.8 KB Updated

File contents

robsonkades/agent-skills/tree/main/skills/java-design-by-contract commit 8a86a937da

Frequently asked questions

npx skillmds@latest add robsonkades/java-design-by-contract