Tutorial by Examples

Some basic types and classes in Java are fundamentally mutable. For example, all array types are mutable, and so are classes like java.util.Data. This can be awkward in situations where an immutable type is mandated. One way to deal with this is to create an immutable wrapper for the mutable type...
An immutable object is an object whose state cannot be changed. An immutable class is a class whose instances are immutable by design, and implementation. The Java class which is most commonly presented as an example of immutability is java.lang.String. The following is a stereotypical example: ...
Using some setters, without setting all needed properties in the constructor(s) public final class Person { // example of a bad immutability private final String name; private final String surname; public Person(String name) { this.name = name; } public String ge...

Page 1 of 1