How do you create an Immutable class like String | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How do you create an Immutable class like String

Immutable class objects can not be modified

2nd Mar 2017, 8:12 AM
harish swami
harish swami - avatar
2 Answers
0
When an object is mutable, attributes are defined when they are created, and never changed after that. Hide instance variables from outside and omit any method that modifies them. Concrete ways are varied among languages.
2nd Mar 2017, 9:44 AM
Twelfty
Twelfty - avatar
0
final class Immutable {}
24th Apr 2017, 12:58 PM
Mike Mather
Mike Mather - avatar