Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2009
    Posts
    28
    Rep Power
    0

    Default how to write user defined class as Immutable?

    String class object is immutable.how to write our own user defined class object as immutable?

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    618
    Rep Power
    4

    Default

    Hi. You can use "final" keyword for this aim. if you want to close access to inside variables you will not be able to make a set's modification in this class.
    Skype: petrarsentev
    http://TrackStudio.com

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default

    Is Google down in your part of the world?
    Immutable object - Wikipedia, the free encyclopedia

    db

  4. #4
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    In short, declare the class as 'public final class ImmutableThing', and all variables too. Can't modify anything then, and that's what makes something immutable. Besides that, google is your friend.
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

Similar Threads

  1. Problem with user defined class in ArrayList
    By anders73 in forum New To Java
    Replies: 4
    Last Post: 04-26-2011, 03:59 PM
  2. Write & Call User-Defined Method
    By lala in forum New To Java
    Replies: 6
    Last Post: 01-23-2011, 04:40 PM
  3. User Defined Method
    By overcranked in forum New To Java
    Replies: 6
    Last Post: 04-09-2010, 01:02 AM
  4. JSP with user-defined java classes
    By adammyth in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 03-05-2010, 06:13 PM
  5. What is an Immutable Class
    By maheshkanda in forum New To Java
    Replies: 3
    Last Post: 02-06-2009, 08:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •