2
我在写注释处理器。我怎样才能得到一个数组的类型?在Java注释处理器中获取数组的类型
@MyAnnotation
int[] iArray;
@MyAnnotation
boolean[] bArray;
@MyAnnotation
FooClass[] fooArray;
据我知道我可以检查它是否是这样的一个数组:
if (element.asType().getKind() == TypeKind.ARRAY) {
// it's an array
// How to check if its an array of boolean or an array integer, etc.?
}
如何获取数组的类型?
基本上我遍历与@MyAnnotation
标注的所有元素,我会做一些特殊的使用数组取决于阵列的类型,这样的事情:
for (Element element : enviroment.getElementsAnnotatedWith(MyAnnotation.class)) {
if (element.getKind() != ElementKind.FIELD)
continue;
if (element.asType().getKind() == TypeKind.ARRAY) {
// it's an array
// How to distinguish between array of boolean or an array integer, etc.?
}
}
Element是什么类型的? – 2014-09-30 15:16:41
元素是'VariableElement' – sockeqwe 2014-09-30 15:17:21
做数组中的第一个元素的一个instaterof ... – StackFlowed 2014-09-30 15:28:22