Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Gail Knight   on Jun 14 In Java Category.

  
Question Answered By: Kellie Bishop   on Jun 14

As far as creating your own class with an immutable object, I'm not sure if
there's a way to lock a class member variable after it's been initialized by the
constructor other than to keep it private and not provide any methods to change
the value.

Immutable objects are generally useful if you want data that can't be changed
when passed into a function. For instance, if you have a regular mutable object
that's passed into a function, the function can alter that object  before it
finishes. There's really nothing particularly exciting about the concept from a
programmer's perspective, but it's probably really useful if you're designing a
language and need object wrappers for primitive types.

Share: 

 

This Question has 8 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on String Object Or get search suggestion and latest updates.


Tagged: