Java – what is the difference between static and non static annotations?

Java's internal classes can be static or non - static A non - static inner class is associated with an instance of a closed class

Annotations are Java interfaces that, like any other class, can be defined in a class Again, they can be declared static or non - static What is the difference between the two choices, how do they use code, and is there any use of one of them?

Example:

public class AnnotationContainer {

  public static @interface StaticAnnotation {}
  public @interface NonstaticAnnotation {}

}

Solution

There is no difference Nested interfaces are always static

This is in JLS sec 8.5 Description in 1 (for class):

And JLS sec 9.5 (for interface):

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>