今天,我想在this documentation之后创建我的第一个注释接口,但是我得到了这个编译器错误
Invalid type for annotation member": public @interface MyAnnotation { Object myParameter; ^^^^^^ }
显然,Object
不能用作注释成员的类型.不幸的是,我找不到任何关于一般情况下可以使用哪些类型的信息.
这是我通过反复试验发现的:
-
String
→ 有效的 -
int
→有效 -
Integer
→ 无效(令人惊讶) -
String[]
→ 有效(令人惊讶) -
Object
→ 无效的
也许有人能解释一下哪些类型是被允许的,以及为什么.