File tree Expand file tree Collapse file tree 1 file changed +3
-1
lines changed
src/main/java/victor/training/cleancode/immutable/basic Expand file tree Collapse file tree 1 file changed +3
-1
lines changed Original file line number Diff line number Diff line change 44import lombok .Value ;
55
66import java .util .ArrayList ;
7+ import java .util .Collections ;
78import java .util .List ;
89import java .util .stream .Stream ;
910
@@ -39,7 +40,8 @@ class Immutable { // acum acest obiect este // "deep immutable"
3940 Other other ;
4041
4142 public List <Integer > getNumbers () {
42- 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
4345 }
4446
4547 public String toString () {
You can’t perform that action at this time.
0 commit comments