8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f3c0a2e commit 3924360Copy full SHA for 3924360
Chapter_13/P269_OptionalInConstructorsArgs/src/modern/challenge/BookAvoid.java
@@ -6,11 +6,20 @@
6
public class BookAvoid {
7
8
private final String title; // cannot be null
9
- private final Optional<String> isbn; // optional field, thus may be empty
+ private final Optional<String> isbn; // optional field, cannot be null
10
11
public BookAvoid(String title, Optional<String> isbn) {
12
this.title = Objects.requireNonNull(title, () -> "Title cannot be null");
13
- this.isbn = isbn;
+
14
+ /*
15
+ if (isbn == null) {
16
+ this.isbn = Optional.empty();
17
+ } else {
18
+ this.isbn = isbn;
19
+ }*/
20
21
+ // or
22
+ this.isbn = Objects.requireNonNullElse(isbn, Optional.empty());
23
}
24
25
public String getTitle() {
0 commit comments