Skip to main content

Repair the Broken Value Class

Challenge on lesson: Checkpoint: Object Contracts

Config is meant to be an immutable settings key, but it is broken: hashCode uses only one field and the constructor accepts nulls. Inside Solution, provide a fixed Config: - final fields String app, String key (both participate in equality) - equals via instanceof pattern comparing both fields - hashCode via Objects.hash(app, key) - constructor throws IllegalArgumentException when app or key is null Then implement static List<String> sortedKeys(List<Config> configs) returning the distinct configs' key values in natural sorted order, using a HashSet for dedup (which only works because Config now keeps its hash contract).

Difficulty: intermediate

Back to lesson: Checkpoint: Object Contracts