Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

11
  • 1
    I'd say you do still need the @NotNull annotation for all 4 formal parameters so that static analysis checkers know your intention that none should be null. There's nothing in the Java language yet that enforces that. You should also be checking that description is not null if you're programming defensively. Commented May 11, 2016 at 22:21
  • 4
    I can still write this code: new Role(null,null,null,null);. With the annotations my IDE and static analysis will warn that null can't be passed into those parameters. Without it I don't find out until I run the code. That's the value of the annotations. Commented May 27, 2016 at 21:00
  • 2
    I'm also in environments where developers can use any IDE or text editor they prefer, its not mutually-exclusive. We then also integrate the maven-pmd-plugin and/or SonarQube into the build process to encourage and highlight, and even gate, code quality issues pre-merge, for example on pull requests. Commented Jun 1, 2016 at 16:41
  • 3
    Optional is not meant to be used as a method argument or private field. See for example: stuartmarks.wordpress.com/2016/09/27/vjug24-session-on-optional Commented Sep 29, 2016 at 12:38
  • 1
    @assylias yes, I found that out later, they say it is not recommended because it won't buy us anything, I can definitely understand their rational. In this case I put here, one could make the argument description not null and client code could pass an empty String, but in many cases it could be handy to distinguish between and empty String and not having a value. Thanks for your comment. I will update the answer. Commented Oct 3, 2016 at 16:04