Hey all,
While practicing with Enthuware, I stumbled on a mock question about serialization of record classes in Java, and it threw me off completely. I thought records, by default, handle serialization just like normal POJOs since they’re implicitly Serializable when their fields are, but the explanation hinted at some subtle differences when custom constructors are involved.
Now I’m second-guessing myself: if I add validation logic in a compact constructor of a record Pips NYT, does it affect how the record behaves when deserialized? And if so, how do we predict that in an exam setting?
Has anyone else encountered this type of question, and how do you typically approach it during the test without overthinking?
Confused by a Question on Record Serialization
Moderator: admin
-
- Posts: 2
- Joined: Tue Aug 05, 2025 11:53 pm
- Contact:
-
- Site Admin
- Posts: 10429
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: Confused by a Question on Record Serialization
There is no need to overthink. Just go through this info:
Taken from Hanumant Deshmukh's OCP Java 17/21 Fundamentals.
So basically, the canonical constructor will be called during deserialization with the values stored in the stream. The end result depends on what the constructor does.
Taken from Hanumant Deshmukh's OCP Java 17/21 Fundamentals.
So basically, the canonical constructor will be called during deserialization with the values stored in the stream. The end result depends on what the constructor does.
Who is online
Users browsing this forum: No registered users and 285 guests