【发布时间】:2020-03-18 18:12:23
【问题描述】:
文件可以在这里找到 - https://github.com/JetBrains/kotlin/blob/master/core/builtins/native/kotlin/String.kt
添加String.kt代码供参考
package kotlin
/**
* The `String` class represents character strings. All string literals in
* Kotlin programs, such as `"abc"`, are
* implemented as instances of this class.
*/
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
/**
* Returns the character of this string at the specified [index].
*
* If the [index] is out of bounds of this string, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
public override fun get(index: Int): Char
public override fun subSequence(startIndex: Int, endIndex: Int): CharSequence
public override fun compareTo(other: String): Int
}
我想了解显示的方法没有任何实现?还请简要介绍一下这段代码是如何工作的?
如果正在使用本机代码。请链接相同的源代码..
【问题讨论】:
-
请将代码分享为格式化文本,而不是图片。
-
@Zabuza 我已链接到图片下方的文件。
-
String 在 JDK 上通过编译器魔术编译为 Java 字符串,因此您可以查看该源代码以了解它是如何工作的。 hg.openjdk.java.net/jdk7u/jdk7u6/jdk/file/8c2c5d63a17e/src/…
-
@Tenfour04 好的,在图书馆里它实际发生在哪里? Kotlin String 到 Java String 类的链接。此外,如果您在同一个 kotlin 包中看到,还有 Array 类。它是如何映射到 Java 数组的?
-
@abitcode 我知道你链接了它,但是如果你直接分享它会增加你的观众和反应,也会增加投票。如果外部资源不可用,它会使问题自成一体。见How to Ask,谢谢。