Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. @Builder
  2. static class Person {
  3. @NonNull
  4. private final String name;
  5. @NonNull
  6. private final Integer age;
  7. }
  8.  
  9. public static void main(String[] args) {
  10. Person.builder()
  11. .name("Fred")
  12. .build(); // java.lang.NullPointerException: age is marked @NonNull but is null
  13. }
  14.  
  15. @Builder
  16. static class Person {
  17. @NonNull
  18. private final String name;
  19. @NonNull
  20. private final Integer age;
  21.  
  22. public static PersonBuilder builder(String name, Integer age) {
  23. return new PersonBuilder().name(name).age(age);
  24. }
  25. }
  26.  
  27. public static void main(String[] args) {
  28. Person.builder("Fred", 11)
  29. .build();
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement