While most objects are mutable, some are not. For example, any bean that provides a setXXX method is
mutable. Immutable objects can be used to define values or attributes that you don't want to be changed.
Example:
public class MyConstant {
private double value;
public MyConstant(double value) {
this.value = value;
}
public double getValue() {
return value;
}
}
This is not the only way to make object immutable, this is one of the ways available.
mutable. Immutable objects can be used to define values or attributes that you don't want to be changed.
Example:
public class MyConstant {
private double value;
public MyConstant(double value) {
this.value = value;
}
public double getValue() {
return value;
}
}
This is not the only way to make object immutable, this is one of the ways available.
0 comments:
Post a Comment