如何修复Kotlin中的过载分辨率歧义(无lambda)? [英] How to fix Overload Resolution Ambiguity in Kotlin (no lambda)?

查看:65
本文介绍了如何修复Kotlin中的过载分辨率歧义(无lambda)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在此行中有超载分辨率歧义"错误:

I am having Overload Resolution Ambiguity error in this line:

departureHourChoice!!.selectionModel.select(currentHourIndex)

供参考:

  • departureHourChoiceChoiceBox<Int>,来自java.scene.control

currentHourIndexInt

.select()方法中发生了过载分辨率的歧义;它已重载,可以接受两种参数:(T obj)(int index).

The Overload Resolution Ambiguity happens in the .select() method; It is overloaded and can accept two kinds of parameters: (T obj) or (int index).

.select()方法允许选择ChoiceBox中的一项,并且您可以通过引用该项或其索引来确定可以选择的项.在这种情况下,我希望通过索引(int)选择它.

The .select() method allows for an item in a ChoiceBox to be selected, and you can determine which one can be selected by referencing to that item or to it's index. In this case, I want it to be selected by Index (int).

这是错误的照片

如何解决超载分辨率的歧义?

How would one resolve the Overload Resolution Ambiguity?

推荐答案

似乎您被此错误可以解决:

  • currentHourIndex框:

lateinit var departureHourChoice: ChoiceBox<Int>
...
val currentHourIndex = 1
departureHourChoice.selectionModel.select(currentHourIndex as Int?)

  • 或将ChoiceBox的声明更改为使用java.lang.Integer而不是Kotlin的Int:

  • or change declaration of ChoiceBox to use java.lang.Integer instead of Kotlin's Int:

    lateinit var departureHourChoice: ChoiceBox<java.lang.Integer>
    ...
    val currentHourIndex = 1
    departureHourChoice.selectionModel.select(currentHourIndex)
    

  • 进一步阅读:

    • 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?

    这篇关于如何修复Kotlin中的过载分辨率歧义(无lambda)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆