我正在使用Swing外觀&感覺使用kotlin。爲了創建一個UI,鞦韆需要有一個靜態方法createUI
具有以下簽名:Kotlin @JvmStatic和意外覆蓋同伴對象
class ButtonUI: BasicButtonUI() {
...
companion object {
@JvmStatic fun createUI(p0: JComponent): ComponentUI {
...
}
}
}
,然後通過反射調用Swing代碼:
m = uiClass.getMethod("createUI", new Class[]{JComponent.class});
不幸的是,上面的代碼不能由kotlin編譯器編譯,因爲:
Error:(88, 9) Kotlin: Accidental override: The following declarations have the same JVM signature (createUI(Ljavax/swing/JComponent;)Ljavax/swing/plaf/ComponentUI;):
fun createUI(c: JComponent): ComponentUI
fun createUI(p0: JComponent!): ComponentUI!
是否有解決此問題的方法案件?
您是否試過'@JvmStatic override fun createUI'? – shiftpsh
@shiftpsh它在對象聲明中不適用。 – dimafeng