World 11 of 26 · Intermediate

🪆 Enums, Records & Nested Types

13 Java concepts, each explained step by step with real code, a common trap and practice questions.

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