kotlin plus运算符的功能定义在哪里?

问题描述 投票:0回答:1

我只是在kotlin源代码中查找Primitives.kt文件的源代码,以查看'plus'运算符的功能代码。

/** Adds the other value to this value. */
public operator fun plus(other: Int): Int

有人可以帮我指导该功能的代码在哪里吗?

kotlin intrinsics
1个回答
0
投票

Primitives.kt中的这些函数被实现为编译器内部函数。这意味着,当编译器遇到此类函数调用时,它将用一些预定义的较低级代码序列或对另一个函数的调用来替换它。

例如,在Kotlin JVM中,此代码中的函数调用Int.plus(Int): Int

fun test(x: Int, y: Int) {
    x.plus(y)
}

被字节码序列替换,如下所示:

    ILOAD 0
    ILOAD 1
    IADD
© www.soinside.com 2019 - 2024. All rights reserved.