LearnFrenzy
Sign in Take a free test

Records, Enums and Sealed Classes · Records, Enums and Sealed Classes MCQ · Question 13

Shallow immutability of records Answer, explanation & discussion

  • MCQ
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 13 Back to Exercise

A record has a component List<String> tags holding an ArrayList. What can still change?

  • A Nothing
  • B The list's contents – the record only fixes the reference; copy it with List.copyOf in the compact constructor Correct
  • C The reference itself
  • D The record's class
Correct Answer: Option B

Records are shallowly immutable.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links