java – 静态和非静态注释之间的区别是什么?

Java的内部类可以是静态的也可以是非静态的.非静态内部类与封闭类的实例相关联.

注释是一种Java接口,与任何其他类一样,它们可以在类中定义.同样,它们可以声明为静态或非静态.这两个选择之间有什么区别,它们在使用代码时的使用方式有何不同,是否有任何使用其中一种选择的情况?

例:

public class AnnotationContainer {

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

}

解决方法

没有任何区别.嵌套接口始终是静态的.

这在JLS Sec 8.5.1中描述(对于类):

A member interface is implicitly static (§9.1.1). It is permitted for the declaration of a member interface to redundantly specify the static modifier.

JLS Sec 9.5(用于接口):

A member type declaration in an interface is implicitly public and static. It is permitted to redundantly specify either or both of these modifiers.

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...