---
title: "Which @NotNull Java annotation should I use?"  
description: "Which @NotNull Java annotation should I use?"  
author: "Anonymous User"  
published: 2015-07-17  
updated: 2015-07-18  
canonical: https://www.mindstick.com/forum/23351/which-notnull-java-annotation-should-i-use  
category: "java"  
tags: ["java"]  
reading_time: 1 minute  

---

# Which @NotNull Java annotation should I use?

I'm looking to make my code more readable [as well as](https://www.mindstick.com/interview/2481/can-you-write-a-java-class-that-could-be-used-both-as-an-applet-as-well-as-an-application) use tooling like IDE code inspection and/or static code [analysis](https://www.mindstick.com/articles/323533/prospective-analysis) (FindBugs and Sonar) to avoid NullPointerExceptions. Many of the tools seem incompatible with each others' @NotNull/@NonNull/@Nonnull annotation and listing all of them in my code would be terrible to read. Any suggestions of which one is the 'best'? Here is the list of equivalent [annotations](https://www.mindstick.com/articles/12141/annotations-in-java-target-and-retention) I've found:\
javax.[validation](https://www.mindstick.com/articles/12234/validation-using-data-annotation-using-entity-framework).constraints.NotNullCreated for [runtime](https://www.mindstick.com/articles/52/creating-timer-at-runtime-in-c-sharp-dot-net) validation, not static analysis.[documentation](https://answers.mindstick.com/qa/30462/what-is-documentation)\
edu.umd.cs.findbugs.annotations.NonNullUsed by Findbugs static analysis and therefore Sonardocumentation\
javax.annotation.NonnullThis might work with Findbugs too, but JSR-305 is inactive.source\
com.[intellij](https://www.mindstick.com/forum/33658/android-device-not-detecting-in-intellij-idea).annotations.NotNullUsed by IntelliJ IDEA IDE for static analysis.documentation\
lombok.NonNullUsed to control [code generation](https://www.mindstick.com/forum/157728/what-is-intermediate-and-target-code-generation-in-a-compiler) in [Project](https://www.mindstick.com/articles/105927/how-to-excel-at-managing-multiple-projects) Lombok.

## Replies

### Reply by Anonymous User

For Android projects you should use android.support.annotation.NonNull and android.support.annotation.Nullable. These and other helpful Android-specific annotations are available in the Support Library.


---

Original Source: https://www.mindstick.com/forum/23351/which-notnull-java-annotation-should-i-use

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
