FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [View Raw Code]   [Original HTTPS Page]

Java-Mastery/Java21/RecordPatterns/Records.md at main · SanaShahSyeda/Java-Mastery · GitHub

Latest commit

 

History

History
21 lines (20 loc) · 606 Bytes

File metadata and controls

21 lines (20 loc) · 606 Bytes

Java Records

  • A record is a special Java class designed to hold immutable data with minimal boilerplate.

  • A record automatically generats:

    • constructor
    • getters (x() instead of getX())
    • equals()
    • hashCode()
    • toString()
  • A record is implicitly:

    • final
    • immutable
    • transparent(data-centric)
  • Java 21 introduces record deconstruction patterns. This lets you extract data directly inside:

    • if
    • switch
    • enhanced switch expressions
    • method parameters
  • Record patterns allow:

    • Deconstruction of immutable data
    • Pattern matching on structured objects

Back | FazBrowse Home | New Git URL