CodeX

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

Follow publication

Member-only story

Know how the Java annotations you use work. Part II: Null safety annotations

Is there anything in the box? Photo by Lia Trevarthen on Unsplash

Null safety is a big concern for Java developers. There’s no point rehashing the regrets of the “inventor” of null, it’s something we must deal with if we want to write programs using Java.

Luckily, there’s an annotation for that. Actually, there are a few different annotations that we can use to specify something must not be null or that it may be null.

The most famous is probably Lombok’s @NonNull. There’s also @NotNull from JetBrains, which also provides @Nullable. The JetBrains annotations are made specifically for use with IntelliJ IDEA, the Java integrated development environment (IDE) from JetBrains.

In Part I of this series, I wrote about how so many Java developers use the annotations in the Spring framework without really understanding how they work. This is, to a lesser extent, also true of annotations from other sources, like the null safety annotations I’ll be going over in this part.

In the previous part, I explained that annotations by themselves don’t actually do anything besides annotate. It is something else in the framework that acts on what the annotation suggests should be done. The compiler, the IDE and other tools can also act on annotations.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

CodeX
CodeX

Published in CodeX

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

Alonso Del Arte
Alonso Del Arte

Written by Alonso Del Arte

is a Java and Scala developer from Detroit, Michigan. AWS Cloud Practitioner Foundational certified

No responses yet

Write a response