IMMUTABLE

IMMUTABLE

View Answers

October 13, 2009 at 4:11 PM

Hi Friend,

To make a class immutable we must restrict changing the state of the class object.We can achieve this through a final and private modifier.Therefore,make all fields final and private.Don't provide any methods that modify the object.

for example,

final class ImmutableClass{
private final int count;
public ImmutableClass(int cout){
count = cout;
}
public int getCount(){
return count;
}
}
public class Immutable{
public static void main(String[] args) {
ImmutableClass cl = new ImmutableClass(5);
System.out.println(cl.getCount());
}
}

Thanks

October 24, 2010 at 10:35 AM

Please see here **Deleted**









Related Tutorials/Questions & Answers:
immutable class
immutable class  How to make a class immutable
String immutable - Java Beginners
String immutable  Why is String immutable?  See here Why String is immutable in Java
Advertisements
ModuleNotFoundError: No module named 'immutable'
ModuleNotFoundError: No module named 'immutable'  Hi, My Python... 'immutable' How to remove the ModuleNotFoundError: No module named 'immutable' error? Thanks   Hi, In your python environment you
IMMUTABLE - Java Interview Questions
IMMUTABLE  How To Make A Class Immutable?  Hi Friend, To make a class immutable we must restrict changing the state of the class...; } } public class Immutable{ public static void main(String[] args
Version of com.dampcake>gson-immutable dependency
List of Version of com.dampcake>gson-immutable dependency
Version of com.qifun>immutable-future_2.10 dependency
List of Version of com.qifun>immutable-future_2.10 dependency
Version of com.qifun>immutable-future_2.11.0-RC4 dependency
List of Version of com.qifun>immutable-future_2.11.0-RC4 dependency
ModuleNotFoundError: No module named 'immutable-collection'
ModuleNotFoundError: No module named 'immutable-collection'  Hi...: No module named 'immutable-collection' How to remove the ModuleNotFoundError: No module named 'immutable-collection' error? Thanks   Hi
ModuleNotFoundError: No module named 'immutable-namespace'
ModuleNotFoundError: No module named 'immutable-namespace'  Hi, My... named 'immutable-namespace' How to remove the ModuleNotFoundError: No module named 'immutable-namespace' error? Thanks   Hi
Mutable and immutable Objects - Java Beginners
Mutable and immutable Objects  Hi, Please tell me about Mutable and immutable Objects. What is mutable object and immutable object and how... we can alter. like any primitive. Immutable are those object whcih we can
what is mutable and immutable object in java ?difference ?
what is mutable and immutable object in java ?difference ?  what is mutable and immutable object in java ?difference
STRING IMMUTABLE - Java Interview Questions
STRING IMMUTABLE  Why string objects are immutable? what is the region behind?i want regione plz replyyyyyyyyy  Hi Friend, JVM maintains... object is immutable. Thanks
ModuleNotFoundError: No module named 'odoo10-addon-user-immutable'
ModuleNotFoundError: No module named 'odoo10-addon-user-immutable'  ...: No module named 'odoo10-addon-user-immutable' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-user-immutable' error? Thanks
ModuleNotFoundError: No module named 'django-immutable-model'
ModuleNotFoundError: No module named 'django-immutable-model'  Hi...: No module named 'django-immutable-model' How to remove the ModuleNotFoundError: No module named 'django-immutable-model' error? Thanks   Hi
ModuleNotFoundError: No module named 'Object-Path-Immutable'
ModuleNotFoundError: No module named 'Object-Path-Immutable'  Hi...: No module named 'Object-Path-Immutable' How to remove the ModuleNotFoundError: No module named 'Object-Path-Immutable' error? Thanks   Hi
ModuleNotFoundError: No module named 'odoo10-addon-user-immutable'
ModuleNotFoundError: No module named 'odoo10-addon-user-immutable'  ...: No module named 'odoo10-addon-user-immutable' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-user-immutable' error? Thanks
ModuleNotFoundError: No module named 'Dict-Path-Immutable'
ModuleNotFoundError: No module named 'Dict-Path-Immutable'  Hi, My... named 'Dict-Path-Immutable' How to remove the ModuleNotFoundError: No module named 'Dict-Path-Immutable' error? Thanks   Hi
ModuleNotFoundError: No module named 'django-immutable-model'
ModuleNotFoundError: No module named 'django-immutable-model'  Hi...: No module named 'django-immutable-model' How to remove the ModuleNotFoundError: No module named 'django-immutable-model' error? Thanks   Hi
ModuleNotFoundError: No module named 'immutable_default_args'
ModuleNotFoundError: No module named 'immutable_default_args'  Hi...: No module named 'immutable_default_args' How to remove the ModuleNotFoundError: No module named 'immutable_default_args' error? Thanks   Hi
ModuleNotFoundError: No module named 'immutable-time-travel'
ModuleNotFoundError: No module named 'immutable-time-travel'  Hi...: No module named 'immutable-time-travel' How to remove the ModuleNotFoundError: No module named 'immutable-time-travel' error? Thanks   Hi
Maven Dependency gson-immutable >> 1.0
You should include the dependency code given in this page to add Maven Dependency of com.dampcake >> gson-immutable version1.0 in your project
Maven Dependency gson-immutable >> 1.1
You should include the dependency code given in this page to add Maven Dependency of com.dampcake >> gson-immutable version1.1 in your project
Maven Dependency gson-immutable >> 1.1.1
You should include the dependency code given in this page to add Maven Dependency of com.dampcake >> gson-immutable version1.1.1 in your project
Maven Dependency gson-immutable >> 1.2
You should include the dependency code given in this page to add Maven Dependency of com.dampcake >> gson-immutable version1.2 in your project
Maven Dependency immutable-future_2.10 >> 0.1
You should include the dependency code given in this page to add Maven Dependency of com.qifun >> immutable-future_2.10 version0.1 in your project
Maven Dependency immutable-future_2.11.0-RC4 >> 0.1
You should include the dependency code given in this page to add Maven Dependency of com.qifun >> immutable-future_2.11.0-RC4 version0.1 in your project
Maven Repository/Dependency: org.webjars.npm | immutable
Maven Repository/Dependency of Group ID org.webjars.npm and Artifact ID immutable. Latest version of org.webjars.npm:immutable dependencies. # Version Release Date 1
Immutable Image using Canvas Class
Immutable Image using Canvas Class       This is the immutable image example which shows how to create the immutable image using canvas. In this example ImageCanvas class
Immutable Image MIDlet Example
Immutable Image MIDlet Example       This is the immutable image example, which shows how to create a immutable image in MIDlet. In this example we are creating
Maven Repository/Dependency: com.dampcake | gson-immutable
Maven Repository/Dependency of Group ID com.dampcake and Artifact ID gson-immutable. Latest version of com.dampcake:gson-immutable dependencies. # Version Release Date You can read more
Maven Repository/Dependency: com.qifun | immutable-future_2.11.0-RC4
Maven Repository/Dependency of Group ID com.qifun and Artifact ID immutable-future_2.11.0-RC4. Latest version of com.qifun:immutable-future_2.11.0-RC4 dependencies. # Version Release Date
Maven Repository/Dependency: com.jcabi | jcabi-immutable
Maven Repository/Dependency of Group ID com.jcabi and Artifact ID jcabi-immutable. Latest version of com.jcabi:jcabi-immutable dependencies. # Version Release Date 1 1.5
Maven Repository/Dependency: com.qifun | immutable-future_2.10
Maven Repository/Dependency of Group ID com.qifun and Artifact ID immutable-future_2.10. Latest version of com.qifun:immutable-future_2.10 dependencies. # Version Release Date You can
org.webjars.npm - immutable version 4.0.0-rc.9 Maven dependency. How to use immutable version 4.0.0-rc.9 in pom.xml?
org.webjars.npm  - Version 4.0.0-rc.9 of immutable Maven dependency? How to use  org.webjars.npm  - Version 4.0.0-rc.9 of immutable in pom.xml? How to use immutable version 4.0.0-rc.9 in pom.xml? Learn to use
Maven dependency for org.webjars.npm - immutable version 4.1.0 is released. Learn to use immutable version 4.1.0 in Maven based Java projects
Maven dependency for  org.webjars.npm  - Version 4.1.0 of immutable released The developers of   org.webjars.npm - immutable project have... version of  org.webjars.npm - immutable library is 4.1.0. Developer can use
Maven dependency for org.webjars.npm - immutable version 4.0.0 is released. Learn to use immutable version 4.0.0 in Maven based Java projects
Maven dependency for  org.webjars.npm  - Version 4.0.0 of immutable released The developers of   org.webjars.npm - immutable project have... version of  org.webjars.npm - immutable library is 4.0.0. Developer can use
Maven dependency for com.jcabi - jcabi-immutable version 1.5 is released. Learn to use jcabi-immutable version 1.5 in Maven based Java projects
Maven dependency for  com.jcabi  - Version 1.5 of jcabi-immutable released The developers of   com.jcabi - jcabi-immutable project have... of  com.jcabi - jcabi-immutable library is 1.5. Developer can use
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for gson-immutable version 1.0
-immutable version 1.0. You can add these depency in your project to get com.dampcake:gson-immutable:1.0 Java library in your project.. Maven, Gradle, SBT, Ivy, Grape, Leiningen and  Buildr Dependency for gson-immutable version 1.0
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for gson-immutable version 1.1.1
-immutable version 1.1.1. You can add these depency in your project to get com.dampcake:gson-immutable:1.1.1 Java library in your project.. Maven, Gradle, SBT, Ivy, Grape, Leiningen and  Buildr Dependency for gson-immutable version 1.1.1
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for gson-immutable version 1.1
-immutable version 1.1. You can add these depency in your project to get com.dampcake:gson-immutable:1.1 Java library in your project.. Maven, Gradle, SBT, Ivy, Grape, Leiningen and  Buildr Dependency for gson-immutable version 1.1
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for gson-immutable version 1.2
-immutable version 1.2. You can add these depency in your project to get com.dampcake:gson-immutable:1.2 Java library in your project.. Maven, Gradle, SBT, Ivy, Grape, Leiningen and  Buildr Dependency for gson-immutable version 1.2
What is Blockchain?
summarize it as the decentralized, consensus-driven, immutable, cryptography
What is Blockchain?
conclusively, we can summarize it as the decentralized, consensus-driven, immutable
StringBuffer related.
StringBuffer related.  how to make StringBuffer as immutable
core java - Java Beginners
core java  hi, we know that String object is immutable in nature so like string object can we create our own object and that object should be immutable i mean we cant modify our own object plzzzzzzzzzzzzz tell me the answer
java interview
java interview  what is infterface? and it is uses? what is ast class? and it is uses? what is ast methods? what is immutable? what is mutable? what are the final class in java? what is the static methods
j2me image application
j2me image application  i can not get the image in my MIDlet .........please tell me the detailed process for creating immutable image without Canvas class
CORE JAVA
CORE JAVA  Static methods can be participated in inheritance? What is static keyword? What is static keyword? How to write code for static factory method? What is mutable and immutable
Java object
Java object  What is mutable object and immutable object?  An Immutable object is a kind of object whose state cannot be modified after... after it is created. The basic way to create an immutable object is to make all
(ii) String and String Buffer Class
between String and StringBuffer 1) String object is immutable

Ads