We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 490f4e1 commit e8fc9d1Copy full SHA for e8fc9d1
1 file changed
src/main/java/victor/training/cleancode/immutable/basic/ImmutableBasic.java
@@ -4,6 +4,7 @@
4
import lombok.Value;
5
6
import java.util.ArrayList;
7
+import java.util.Collections;
8
import java.util.List;
9
import java.util.stream.Stream;
10
@@ -39,7 +40,8 @@ class Immutable { // acum acest obiect este // "deep immutable"
39
40
Other other;
41
42
public List<Integer> getNumbers() {
- return new ArrayList<>(numbers); // #1 clona in getter: 1) misleading pt caller, 2) ineficient cu memoria
43
+// return new ArrayList<>(numbers); // #1 clona in getter: 1) misleading pt caller, 2) ineficient cu memoria
44
+ return Collections.unmodifiableList(numbers); // #2 Decorator™️ Pattern: un wrapper peste lista originala care arunca ex la orice modificare incerci
45
}
46
47
public String toString() {
0 commit comments