首页 文章

Kotlin中的Java注释参数

提问于
浏览
10

我正在尝试使用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>

1 回答

  • 8

    我找到了解决方案 . 语法似乎是这样的:

    [View(url=array("/"), parent=javaClass<RootView>())]
    class FrontView() : Component() {
    }
    

相关问题