From cb1b3d5a5c444f1083b2591f47cba61b715aa15f Mon Sep 17 00:00:00 2001 From: nguyennamthai Date: Tue, 30 Oct 2018 04:11:57 +0700 Subject: [PATCH] Bael 2285 (#5568) * Fix a division method mistake * Spring null-safety --- .../java/org/baeldung/nullibility/Person.java | 33 +++++++++++++++++++ .../baeldung/nullibility/package-info.java | 6 ++++ 2 files changed, 39 insertions(+) create mode 100644 spring-all/src/main/java/org/baeldung/nullibility/Person.java create mode 100644 spring-all/src/main/java/org/baeldung/nullibility/package-info.java diff --git a/spring-all/src/main/java/org/baeldung/nullibility/Person.java b/spring-all/src/main/java/org/baeldung/nullibility/Person.java new file mode 100644 index 0000000000..08c77c9e9c --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/nullibility/Person.java @@ -0,0 +1,33 @@ +package org.baeldung.nullibility; + +import org.springframework.lang.NonNull; +import org.springframework.lang.Nullable; + +public class Person { + @NonNull + private String fullName; + @Nullable + private String nickName; + + void setFullName(String fullName) { + if (fullName != null && fullName.isEmpty()) { + fullName = null; + } + this.fullName = fullName; + } + + void setNickName(String nickName) { + if (nickName != null && nickName.isEmpty()) { + nickName = null; + } + this.nickName = nickName; + } + + String getFullName() { + return fullName; + } + + String getNickName() { + return nickName; + } +} diff --git a/spring-all/src/main/java/org/baeldung/nullibility/package-info.java b/spring-all/src/main/java/org/baeldung/nullibility/package-info.java new file mode 100644 index 0000000000..446f2e316e --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/nullibility/package-info.java @@ -0,0 +1,6 @@ +@NonNullApi +@NonNullFields +package org.baeldung.nullibility; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file