Objects.nonNull()
Tom Hawtin
tom.hawtin at oracle.com
Fri Jan 14 20:18:59 UTC 2011
On 14/01/2011 11:30, Stephen Colebourne wrote:
> These are prior art that users are familiar with, just as much as the JDK.
There is actually prior art in JSRs.
JSR 305: Annotations for Software Defect Detection
Used @Nonnull. In normal circumstances, we would expect this
annotation and the method to be next to each other together.
(Note the lowercase. This agrees with most of the JDK, although as
ever NIO does something different. The capitalisation is a mistake in
Josh Bloch's contribution.)
JSR 303: Bean Validation
Uses @NotNull
>
> 4) Fluency
> The Objects.notNull code is designed for writing fluent code that
> asserts the non-null status of the value.
>
> public void process(String foo) {
> if (nonNull(foo).length()> 3) { ... }
> }
>
> This is a style/taste thing. Personally I prefer:
>
> public void process(String foo) {
> Validate.notNull(foo);
> if (foo.length()> 3) { ... }
> }
I don't think many people would be tempted to write the first example.
> 5) Now
> *** If you are time-pressured, I'd recommend removing this method from v7. ***
Agreed. Better to let projects do their own thing rather than inflict
yet another broken method that can never be changed.
Tom
More information about the core-libs-dev
mailing list