Kotlin's kotlin.String
type is currently defined as follows (1.1.2) :
public class String : Comparable<String>, CharSequence {
companion object {}
// Operator and override function definitions.
}
Some extensions defined on kotlin.String
cast the receiving instance to the java.lang.String
type to forward method invocations. For example (1.1.2) :
@kotlin.internal.InlineOnly
public inline fun String.toLowerCase(): String = (this as java.lang.String).toLowerCase()
However, nothing in the kotlin.String
type definition makes it clear to me that this cast is guaranteed to succeed.
In Kotlin/JVM kotlin.String
is one of the mapped types - a type that is represented with some existing JDK class in runtime.
Therefore a cast between kotlin.String
and java.lang.String
succeeds in runtime, even though these are two unrelated types from the point of Kotlin type system.
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.