我在此行中遇到Overload Resolution Ambiguity错误:
departureHourChoice!!.selectionModel.select(currentHourIndex)
供参考:
departureHourChoice
是ChoiceBox<Int>
,来自java.scene.control
currentHourIndex
是Int
过载分辨率歧义发生在.select()
方法中;它已重载,可以接受两种参数:(T obj)
或(int index)
。
.select()
方法允许选择ChoiceBox
中的项目,您可以通过引用该项目或其索引来确定可以选择哪个项目。在这种情况下,我希望它由Index(int
)选择。
如何解决过载分辨率歧义?
答案 0 :(得分:9)
您可能会遇到this bug作为解决方法:
框currentHourIndex
:
lateinit var departureHourChoice: ChoiceBox<Int>
...
val currentHourIndex = 1
departureHourChoice.selectionModel.select(currentHourIndex as Int?)
或更改ChoiceBox
的声明以使用java.lang.Integer
而不是Kotlin的Int
:
lateinit var departureHourChoice: ChoiceBox<java.lang.Integer>
...
val currentHourIndex = 1
departureHourChoice.selectionModel.select(currentHourIndex)
进一步阅读:
答案 1 :(得分:0)
尝试转换为Int
:
departureHourChoice!!.selectionModel.select(currentHourIndex as Int)
答案 2 :(得分:0)
在类似情况下针对我的解决方案是在您的导入中定义例如: 将kotlin.math.sqrt导入为kotsqrt
然后用作: val a = kotsqrt(2.3)