Make CharSequence.length a function instead of property
And String.length as well. This is done for JVM interoperability: java.lang.CharSequence is an open class and has a function 'length()' which should be implemented in subclasses somehow. A minor unexpected effect of this is that String.length() is now a compile-time constant (it wasn't such as a property because properties are not supported in compile-time constant evaluation) #KT-3571 Fixed
This commit is contained in:
@@ -64,6 +64,9 @@ public fun String?.orEmpty(): String = this ?: ""
|
||||
public val String.indices: IntRange
|
||||
get() = 0..length() - 1
|
||||
|
||||
public val CharSequence.length: Int
|
||||
get() = length()
|
||||
|
||||
/**
|
||||
* Returns a subsequence specified by given set of indices.
|
||||
*/
|
||||
|
||||
@@ -2,9 +2,6 @@ package kotlin
|
||||
|
||||
import java.io.StringReader
|
||||
import java.util.ArrayList
|
||||
import java.util.HashMap
|
||||
import java.util.HashSet
|
||||
import java.util.LinkedList
|
||||
import java.util.Locale
|
||||
import java.nio.charset.Charset
|
||||
|
||||
@@ -30,8 +27,6 @@ public fun String.toUpperCase(): String = (this as java.lang.String).toUpperCase
|
||||
|
||||
public fun String.toLowerCase(): String = (this as java.lang.String).toLowerCase()
|
||||
|
||||
public fun String.length(): Int = (this as java.lang.String).length()
|
||||
|
||||
public fun String.toCharArray(): CharArray = (this as java.lang.String).toCharArray()
|
||||
|
||||
public fun String.format(vararg args: Any?): String = java.lang.String.format(this, *args)
|
||||
@@ -132,10 +127,6 @@ public fun CharSequence.charAt(index: Int): Char = (this as java.lang.CharSequen
|
||||
|
||||
public fun CharSequence.subSequence(start: Int, end: Int): CharSequence? = (this as java.lang.CharSequence).subSequence(start, end)
|
||||
|
||||
public fun CharSequence.toString(): String? = (this as java.lang.CharSequence).toString()
|
||||
|
||||
public fun CharSequence.length(): Int = (this as java.lang.CharSequence).length()
|
||||
|
||||
public val CharSequence.size: Int
|
||||
get() = this.length
|
||||
|
||||
|
||||
Reference in New Issue
Block a user