Example with mutable refs

suggest change

In this case class Point is mutable and some user can modify state of object of this class.

class Point {
private int x, y;

public Point(int x, int y) {
    this.x = x;
    this.y = y;
}

public int getX() {
    return x;
}

public void setX(int x) {
    this.x = x;
}

public int getY() {
    return y;
}

public void setY(int y) {
    this.y = y;
}
}

//...

public final class ImmutableCircle {
private final Point center;
private final double radius;

public ImmutableCircle(Point center, double radius) {
    // we create new object here because it shouldn't be changed
    this.center = new Point(center.getX(), center.getY());
    this.radius = radius;
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Immutable class:
* Example with mutable refs

Table Of Contents
8 Arrays
10 Maps
11 Strings
25 JAXB
29 Enums
32 Audio
41 Scanner
63 Logging
75 Lists
78 Sets
89 JAX-WS
96 XJC
98 Process
106 Modules
114 Applets
122 JNDI
139 JavaBean
141 Literals
144 Packages
150 JMX
153 JShell
159 Sockets
167 Enum Map
171 Immutable class
175 Hashtable
177 SortedMap