Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Was javax's NotNull removed in Java 8?

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?

like image 375
Rogue Avatar asked Jun 24 '14 18:06

Rogue


People also ask

Which Java annotation is newly introduced 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.

How do you use NotNull annotation in Java?

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.

What is the difference between @NotNull and @NotEmpty?

@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.

What does javax validation constraints NotNull do?

@NotNull validates that the annotated property value is not null. @AssertTrue validates that the annotated property value is true.


Video Answer


1 Answers

javax.validation is not part of Java 8, it is part of Java EE, and is still included in Java EE 7

like image 162
Jim Garrison Avatar answered Sep 24 '22 14:09

Jim Garrison