How to create a Immutable class?

Discussion in 'Strings, I/O, Formatting, Parsing' started by Harikrishna123, Mar 19, 2010.

  1. Harikrishna123

    Harikrishna123 New Member

    Is this possible to create a our own immutable class? If yes how can we do that?
     
  2. rajeshbabu.y

    rajeshbabu.y New Member

    Re: Immutable

    yes we can make a class a immutable


    public class final ClassName
    {
    ---
    --- all properties must be final and private
    private final int i =10;

    ---
    --- all behaviours must be final
    }
     
  3. anneroberts

    anneroberts Member

    1. Announce the class Concerning illustration last thus it can't be stretched out.
    2. Make know fields private thereabouts that regulate right is not permitted.
    3. Don't give setter techniques to variables.
    4. Aggravate all alterable fields last thereabouts that its esteem could make doled out main once.
     

Share This Page