Looking at the documentation for NotNull
under Java 7, you can see javax.validation.constraints.NotNull
is a valid and documented annotation. However upon navigating to the same page for Java 8, I receive a 404.
Netbeans suggests to import com.avaje.ebean.validation.NotNull
, which is not what I want (it doesn't support nearly as many placements).
I've heard of the tag NonNull
instead, but I can't find java documentation nor can I import it in netbeans. What am I meant to be using in Java 8?
Java 8 has included two new features repeating and type annotations in its prior annotations topic. In early Java versions, you can apply annotations only to declarations. After releasing of Java SE 8 , annotations can be applied to any type use. It means that annotations can be used anywhere you use a type.
The @NotNull annotation is, actually, an explicit contract declaring that: A method should not return null. Variables (fields, local variables, and parameters) cannot hold a null value.
@NotNull: a constrained CharSequence, Collection, Map, or Array is valid as long as it's not null, but it can be empty. @NotEmpty: a constrained CharSequence, Collection, Map, or Array is valid as long as it's not null, and its size/length is greater than zero.
@NotNull validates that the annotated property value is not null. @AssertTrue validates that the annotated property value is true.
javax.validation
is not part of Java 8, it is part of Java EE, and is still included in Java EE 7
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With