【发布时间】:2015-10-08 12:14:06
【问题描述】:
我想在 Groovy 中测试我的 Java 自定义注释,但由于字符问题而没有管理它。
Groovyc:期望 'a' 是 char 类型的内联常量,而不是 @MyAnnotation 中的字段表达式
我知道groovy中的char被指定为
'a' as char
我的Java自定义注解
@Target({FIELD})
@Retention(RUNTIME)
@Documented
public @interface MyAnnotation {
char someChar() default '#';
}
不工作 Groovy 代码
class Foo {
@MyAnnotation(someChar = 'a' as char)
Object hoo
}
如果将 char 提取为常量,它也不起作用。
【问题讨论】:
-
char在 Groovy 语言中处于不利地位,在大多数情况下占主导地位的是String的形式 -
看来不把类型改成
String就不行了:/
标签: java groovy annotations