java - 我无法理解 kotlin 中 string.kt 的源代码实现

标签 java open-source kotlin source-code-protection kotlin-android-extensions

在kotlin源码中,我看不懂String.kt的length是怎么实现的,如下:

package kotlin                                                  
public class String : Comparable<String>, CharSequence {
companion object {}

/**
 * Returns a string obtained by concatenating this string with the string representation of the given [other] object.
 */
public operator fun plus(other: Any?): String

public override val length: Int

public override fun get(index: Int): Char

public override fun subSequence(startIndex: Int, endIndex: Int): CharSequence

public override fun compareTo(other: String): Int}

var len:Int = "abc".length;//len = 3 在哪里运行长度??

在哪里实现长度函数?

最佳答案

字符串函数是 Kotlin 认为的 Intrinsic 函数的示例。它们是根据它们运行的​​平台定义的,您将无法在源代码中找到它们的实现。

对于 JVM,它们将直接映射到相应的原生 java.lang.String 方法。这确保没有运行时开销,并利用在 Java 标准库中完成的优化。

关于java - 我无法理解 kotlin 中 string.kt 的源代码实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44522697/

相关文章:

java - 在 Java 中使 GUI 适应屏幕尺寸

Java字符串解析与不同的正则表达式来分割

java - 获取自定义 JPanel 以显示自定义 JComponents (Java Swing)

C++ 开源项目

android - 获取不允许 apk 运行的编译错误

java - 除非打印出来,否则值不会在 while 循环中更新

open-source - 为基于 XSD 的标准选择开源许可证

java - Spring Cloud zuul/刷新抛出500错误

kotlin - 使用Jackson使用模式反序列化Property

Android Room 一对多关系查询反向