Kotlin中的Java注释参数
我正在试验Kotlin,并且有一个下面的Java注释
@Target( { TYPE }) @Retention(RUNTIME) public @interface View { String[] url() default ""; Class<? extends Component> parent() default Component.class; }
在Java代码中,它被用于以下的方式
@View(url="/", parent=RootView.class) public class FrontView extends Component { }
Kotlin是如何表达的? 我努力了
[View(url=Array<String>("/"), parent=Class<RootView>)] class FrontView : Component() { }
但它不编译。 我只有类型不匹配的错误。
Type mismatch. Required: jet.Array<jet.String?>? Found: jet.Array<T>
和
Type mismatch Required: java.lang.Class<out net.contextfw.web.application.component.Component?>? Found: java.lang.Class<T>
我找到了解决方案。 语法看起来像这样:
[View(url=array("/"), parent=javaClass<RootView>())] class FrontView() : Component() { }