Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kotlin 查找数组中对象的索引而不是对象本身_Kotlin - Fatal编程技术网

Kotlin 查找数组中对象的索引而不是对象本身

Kotlin 查找数组中对象的索引而不是对象本身,kotlin,Kotlin,我有一个对象数组(称为Image的对象),我想在数组中找到符合特定条件的对象索引。相反,我当前的代码返回对象本身,而不是数组中的索引: val originalImage = imagesArray.find {it.position == 2} 我的图像类: data class Image ( val position: Int? = 0, val coor: IntArray = intArrayOf(0, 0) ) { override fun equals(o

我有一个对象数组(称为Image的对象),我想在数组中找到符合特定条件的对象索引。相反,我当前的代码返回对象本身,而不是数组中的索引:

val originalImage = imagesArray.find {it.position == 2}
我的图像类:

data class Image (
    val position: Int? = 0,
    val coor: IntArray = intArrayOf(0, 0)
) {
    override fun equals(other: Any?): Boolean {
        return super.equals(other)
    }

    override fun hashCode(): Int {
        return super.hashCode()
    }
}

我试图在数组中找到一个位置等于2的图像对象,并返回其索引。

哦,你说得对,非常感谢