Reputation: 11055
How to use @NonNull
annotations on List
items.
let consider, if i want to force A non-null list of Strings
This is how we can declare that : @NonNull List<String>
what if we want to force, A list of non-null Strings.
How we can do that ?
Upvotes: 1
Views: 2551
Reputation: 11055
@NonNull
Annotation are from the The Checker Framework.
The Framework provides a number of Annotations that could benefit developers to write clean code.
@NonNull Annotation – The compiler can determine cases where a code path might receive a null value.
Java 8 Annotation Improvements :
Prior to java 8 , annotations were only allowed on definitions.
Java SE 8 allows type annotations anywhere that a type is used.
A list of non-null Strings can be difine as List<@NonNull String>
Reference : Section 2.1
Upvotes: 6