🪆 Enums, Records & Nested Types
13 Java concepts, each explained step by step with real code, a common trap and practice questions.
- Enum basicsFixed set of constants; values(), valueOf(), ordinal(), name().
- Enums with fields & methodsConstructors (implicitly private), fields, methods, constant-specific bodies.
- Enums in switchExhaustive switch expressions over enums.
- EnumSet & EnumMapFast, compact collections keyed by enums.
- Enum singletonsWhy a single-element enum is the safest singleton.
- RecordsTransparent data carriers: auto constructor, accessors, equals, hashCode, toString.
- Compact constructors & validationValidating or normalizing record components.
- Record limitationsImplicitly final, fields final, cannot extend classes, shallowly immutable.
- Static nested classesDo not hold a reference to the outer instance.
- Inner classesTied to an outer instance; Outer.this; memory-leak risk.
- Local classesClasses declared inside a method.
- Anonymous classesOne-off implementations; how they differ from lambdas (this, state).
- Object cloningCloneable, shallow vs deep copy, prefer copy constructors.