How can you make a class immutable


  • 0
    N

    By making setter methods private, one can make a class as immutable. Once the attribute values are set during object creation, then those attribute values cannot be modified at runtime. Values like authentication information etc can be stored in these kind of immutable objects


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.