Stephan Schroeder
05/03/2019, 12:57 PMfun main() {
val result: String = "xY"
println("${result.toUpperCase()}-${result.toString()}")
}
fun String.toUpperCase() = "overridde_toUpperCase"
fun String.toString() = "overridde_toString"
leads to output overridde_toUpperCase-xY
Paulius Ruminas
05/03/2019, 12:59 PM/**
* The root of the Kotlin class hierarchy. Every Kotlin class has [Any] as a superclass.
*/
public open class Any {
/**
* Indicates whether some other object is "equal to" this one. Implementations must fulfil the following
* requirements:
*
* * Reflexive: for any non-null value `x`, `x.equals(x)` should return true.
* * Symmetric: for any non-null values `x` and `y`, `x.equals(y)` should return true if and only if `y.equals(x)` returns true.
* * Transitive: for any non-null values `x`, `y`, and `z`, if `x.equals(y)` returns true and `y.equals(z)` returns true, then `x.equals(z)` should return true.
* * Consistent: for any non-null values `x` and `y`, multiple invocations of `x.equals(y)` consistently return true or consistently return false, provided no information used in `equals` comparisons on the objects is modified.
* * Never equal to null: for any non-null value `x`, `x.equals(null)` should return false.
*
* Read more about [equality](<https://kotlinlang.org/docs/reference/equality.html>) in Kotlin.
*/
public open operator fun equals(other: Any?): Boolean
/**
* Returns a hash code value for the object. The general contract of `hashCode` is:
*
* * Whenever it is invoked on the same object more than once, the `hashCode` method must consistently return the same integer, provided no information used in `equals` comparisons on the object is modified.
* * If two objects are equal according to the `equals()` method, then calling the `hashCode` method on each of the two objects must produce the same integer result.
*/
public open fun hashCode(): Int
/**
* Returns a string representation of the object.
*/
public open fun toString(): String
}
toString
exists on type Any
which all objects inherit from thus you can not override it. toUpperCase
does not exist.Stephan Schroeder
05/03/2019, 1:00 PMr2vq
05/03/2019, 1:00 PMString.toUpperCase()
is an extension function. String.toString()
is a method.
public actual inline fun String.toUpperCase(): String = (this as java.lang.String).toUpperCase()
jacob
05/03/2019, 1:01 PMorg.jetbrains.kotlin/kotlin-stdlib/1.3.21/b8815e48fb45e94821287365bd9ce8623f459ac7/kotlin-stdlib-1.3.21-sources.jar!/kotlin/text/StringsJVM.kt
Paulius Ruminas
05/03/2019, 1:02 PMStephan Schroeder
05/03/2019, 1:02 PMStephan Schroeder
05/03/2019, 1:03 PMjacob
05/03/2019, 1:03 PMPaulius Ruminas
05/03/2019, 1:04 PM/**
* 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
}
Stephan Schroeder
05/03/2019, 1:04 PMPaulius Ruminas
05/03/2019, 1:07 PMStephan Schroeder
05/03/2019, 1:09 PMPaulius Ruminas
05/03/2019, 1:12 PMStephan Schroeder
05/03/2019, 1:17 PMDias
05/03/2019, 1:21 PMr2vq
05/03/2019, 1:31 PMRuckus
05/03/2019, 1:46 PMr2vq
05/03/2019, 2:06 PMStephan Schroeder
05/03/2019, 2:53 PM