Skip to content

Instantly share code, notes, and snippets.

import javax.annotation.Nonnull;
import javax.annotation.meta.TypeQualifierDefault;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.PACKAGE)
@Nonnull
@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER})
import javax.annotation.Nonnull;
import javax.annotation.meta.When;
public class Message {
private final String greetingMessage = "Hello ";
@Nonnull
public String getEchoMessage() {
return greetingMessage;
import javax.annotation.Nonnull;
import javax.annotation.meta.When;
public class Message {
private final String greetingMessage = "Hello ";
@Nonnull(when = When.ALWAYS) //When.ALWAYS is default option and makes the annotated type as non-nullable
public String getEchoMessage() {
return greetingMessage;
}
public class Message {
private final String greetingMessage = "Hello ";
public String getEchoMessage() {
return greetingMessage;
}
}