How to get class annotation in java?

The default retention policy is RetentionPolicy.CLASS which means that, by default, annotation information is not retained at runtime:

Annotations are to be recorded in the class file by the compiler but need not be retained by the VM at run time. This is the default behavior.

Instead, use RetentionPolicy.RUNTIME:

Annotations are to be recorded in the class file by the compiler and retained by the VM at run time, so they may be read reflectively.

...which you specify using the @Retention meta-annotation:

@Retention(RetentionPolicy.RUNTIME)
public @interface NewAnnotationType {
}