java - 注解 String[] oneArr();与 String[][] twoArr();声明

标签 java arrays annotations

我有以下类型的注释:

 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/

相关文章:

java - 如何在android中实现应用内支付?

java - 如何模拟局部最终变量

java - 什么是 REST API 和用户角色设计最佳实践?

c++ - 通过引用线程传递数组的问题

java - 服务(java 文件)中的字段需要 Repository 类型的 bean

java - 删除注释会导致运行时崩溃吗?

java - 具有 onclick 帮助的 Recyclerview

java - 设置多项式的结构

c++ - 数组是如何传递的?

注释和静态 block 的java处理顺序