简体   繁体   中英

I can't understand source code implementation of string.kt in kotlin

In kotlin source code, I can't understand how to implement of length of String.kt , it is as following:

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 where to run the length??

where to implement the length function?

The string functions are examples of what Kotlin considers Intrinsic functions. They are defined based on the platform they are running on and you won't be able to find an implementation of them in the source code.

For the JVM they will be directly mapped to the corresponding native java.lang.String methods. This ensures there is no runtime overhead and leverages the optimizations done in the java standard library.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM