Meaning of “shallowly immutable” in the documentation of Record in Java 14
问题 I am reading the documentation of Records and don't understand the term "shallowly immutable". What do we mean by shallowly immutable ? And if it's immutable why we need a copy constructor? Why two "Hello Worlds!"? For all record classes, the following invariant must hold: if a record R's components are c1, c2, ... cn, then if a record instance is copied as follows: R copy = new R(r.c1(), r.c2(), ..., r.cn()); // copy constructor ? then it must be the case that r.equals(copy) . 回答1: Shallowly