File tree Expand file tree Collapse file tree
main/java/com/baeldung/immutable
test/java/com/baeldung/immutable/default_ Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .baeldung .immutable .default_ ;
2+
3+ import org .immutables .value .Value ;
4+
5+ @ Value .Immutable (prehash = true )
6+ public abstract class Person {
7+
8+ abstract String getName ();
9+
10+ @ Value .Default
11+ Integer getAge () {
12+ return 42 ;
13+ }
14+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .immutable .parameter ;
2+
3+
4+ import org .immutables .value .Value ;
5+
6+ @ Value .Immutable
7+ public abstract class Person {
8+
9+ @ Value .Parameter
10+ abstract String getName ();
11+
12+ @ Value .Parameter
13+ abstract Integer getAge ();
14+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .immutable .prehash ;
2+
3+ import org .immutables .value .Value ;
4+
5+ @ Value .Immutable (prehash = true )
6+ public abstract class Person {
7+ abstract String getName ();
8+ abstract Integer getAge ();
9+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .immutable .default_ ;
2+
3+ import org .junit .Test ;
4+
5+ import static org .assertj .core .api .Assertions .assertThat ;
6+
7+ public class ImmutablePersonDefaultTest {
8+
9+ @ Test
10+ public void whenInstantiating_shouldUseDefaultValue () throws Exception {
11+
12+ final com .baeldung .immutable .default_ .ImmutablePerson john = com .baeldung .immutable .default_ .ImmutablePerson .builder ().name ("John" ).build ();
13+
14+ assertThat (john .getAge ()).isEqualTo (42 );
15+
16+ }
17+ }
You can’t perform that action at this time.
0 commit comments