Skip to main content

Checkpoint: Class-token container

Challenge on lesson: Checkpoint: The Heterogeneous Type-Safe Container

Inside Solution, implement public static class Types — the type-safe heterogeneous container: 1. Private Map<Class<?>, Object> data = new HashMap<>(). 2. public <T> void put(Class<T> type, T value) — store under the token. 3. public <T> T get(Class<T> type) — retrieve via type.cast(...) so the returned value is genuinely a T (no unchecked warnings). 4. public <T> boolean has(Class<T> type) — true iff a value was put for that token. Retrieval must be exact: two different tokens hold two different values, and each get() returns the value stored under ITS OWN token.

Difficulty: advanced

Back to lesson: Checkpoint: The Heterogeneous Type-Safe Container