gpt4 book ai didi

java - 错误 :Kotlin:Out-projected type 'JComboBox<*>' prohibits the use of '@BeanProperty public open fun setModel(p0: ComboBoxModel!)

转载 作者:行者123 更新时间:2023-11-30 05:21:34 25 4
gpt4 key购买 nike

我是 Kotlin 新手,正在将一些 Java 代码翻译成它。

我想出的代码是:

val comboBox: JComboBox<*> = JComboBox<Any?>()
comboBox.font = Font("苹方", Font.PLAIN, 15)
comboBox.setModel(DefaultComboBoxModel<Any?>(s)) /*
error:Out-projected type 'JComboBox<*>' prohibits the use of '@BeanProperty public open fun setModel(p0: ComboBoxModel<E!>!): Unit defined in javax.swing.JComboBox'
*/
comboBox.setBounds(341, 73, 170, 28)
panel.add(comboBox)

但我收到以下错误:

Error:Kotlin:Out-projected type 'JComboBox<*>' prohibits the use of '@BeanProperty public open fun setModel(p0: ComboBoxModel<E!>!)

我做错了什么?

为了完整起见,这是我原来的java代码:

JComboBox comboBox = new JComboBox();
comboBox.setFont(new Font("苹方", Font.PLAIN, 15));
comboBox.setModel(new DefaultComboBoxModel(s));
comboBox.setBounds(341, 73, 170, 28);
panel.add(comboBox);

最佳答案

之前的代码:

val comboBox: JComboBox<*> = JComboBox<Any?>()

应更改为:

val comboBox = JComboBox<Any?>()

关于java - 错误 :Kotlin:Out-projected type 'JComboBox<*>' prohibits the use of '@BeanProperty public open fun setModel(p0: ComboBoxModel<E! >!),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59489897/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com