Tag: 嵌套

在Kotlin嵌套注释

在Java中,可以创建如下所示的嵌套注释: public @interface InnerInnotation { String value(); } public @interface OuterAnnotation { InnerAnnotation[] value() default { @InnerAnnotation(“Hello”), @InnerAnnotation(“World”) } } annotation class InnerAnnotation(val value: String) 但是当我试图在Kotlin中做同样的事情时,我得到一个编译错误: annotation class OuterAnnotation( // Next line doesn’t compile: “Annotation class cannot be instantiated” val value: Array = arrayOf(InnerAnnotation(“Test”)) ) 但是,单个实例注记字段正常工作: annotation class OuterAnnotation( val value: InnerAnnotation = InnerAnnotation(“Hello World”) […]