我在这一行中遇到Overload Resolution Ambiguity错误:
departureHourChoice!!.selectionModel.select(currentHourIndex)
以供参考:
-
departureHourChoice
是ChoiceBox<Int>
,来自java.scene.control
-
currentHourIndex
是Int
-
过载分辨率歧义发生在
.select()
方法中;它被重载并且可以接受两种参数:(T obj)
或(int index)
. -
.select()
方法允许选择ChoiceBox
中的项目,您可以通过引用该项目或其索引来确定可以选择哪个项目 . 在这种情况下,我希望它由Index(int
)选择 . -
这是错误的照片
如何解决过载分辨率模糊?
3 回答
您似乎被this bug击中,作为一种解决方法,您可以:
currentHourIndex
:ChoiceBox
的声明以使用java.lang.Integer
而不是Kotlin的Int
:进一步阅读:
Why is Integer parameter of Java method mapped to Int and not platform type?
Kotlin: What can I do when a Java library has an overload of both primitive and boxed type?
尝试转换为
Int
:在类似的情况下我的解决方案是在您的导入中定义例如:import kotlin.math.sqrt as kotsqrt
然后用作:val a = kotsqrt(2.3)