一些人
我看到 @Interface 用于声明注释。@Interface 也可以用来声明注释以外的东西吗?
如果没有,为什么不直接称它为@Annotation 之类的?
用户1803551
可以有不是注释的 Java 接口吗?
是的,常规interface
的:
public interface MyInterface {...}
@Interface 也可以用来声明注释以外的东西吗?
不,@interface
定义一个注释。并且要小心字母大小写 - 它是小写字母@interface
,而不是@Interface
.
为什么不直接称它为@Annotation 之类的?
因为注解是一个类型的接口,看到答案我给你的其他问题,
一个注解类型声明指定了一个新的注解类型,一种特殊的接口类型。
(粗体强调的是我的)和教程:
注解类型是接口的一种形式
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
编辑于
我来说两句