Immutable Class


Performance and scalability: Immutable Class

  1. Immutable Class (4 messages)

    Can anybody answer me?
    What is an Immutable Class, and how to make a Class explicitly "Immutable"?

    Threaded Messages (4)

  2. public final class[ Go to top ]

    The term immutable is not appropriate.
    But unfortunately this is how it is termed :-(
  3. public final class[ Go to top ]

    The term immutable is used to be mean that once an object is created, its content cannot be changed

    As some one has replied "String" class is a best example of an immutable class

    To create a object which is immutable u need to make sure that the following conditions are met

    1)The Class should be final
    2)The Properties of the class should be private and should not have any setter methods
    The above mentioned are bare minimum conditions that needs to be satisfied to make the object immutable
  4. let's see[ Go to top ]

    The ideal name should have been 'RememberWhenYouModifyMeYouArePayingByCreatingNewObjects' ;)

    String class is the most common example isn't it?
    If u ever used the method <somestringobject>.replace u know what that-can't-pronounce-name is doing :)
  5. Immutable Class[ Go to top ]

    immutable class is something whose state can not be changed e.g. String