我有以下类型的注释:
public @interface A {
String[] oneArr();
String[][] twoArr();
}
为什么第一种String[] oneArr();
有效,而第二种String[][] to Array();
无效?
最佳答案
来自JLS (Java Language Specification) :
It is a compile-time error if the return type of a method declared in an annotation type is not one of the following: a primitive type, String, Class, any parameterized invocation of Class, an enum type (§8.9), an annotation type, or an array type (§10) whose element type is one of the preceding types.
这是来自 Eclipse java 编译器的错误消息,它更清楚一些:
Invalid type String[][] for the annotation attribute A.twoArr; only primitive type, String, Class, annotation, enumeration are permitted or 1-dimensional arrays thereof
关于java - 注解 String[] oneArr();与 String[][] twoArr();声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19135186/