Unify operations on Array<T> and Array<out T> (copyOf, copyOfRange) which return the same type as the receiver.

This commit is contained in:
Ilya Gorbunov
2015-08-28 19:02:49 +03:00
parent a3056bea1a
commit 89df3925fa
3 changed files with 31 additions and 30 deletions
+4 -20
View File
@@ -203,8 +203,8 @@ public fun ShortArray.binarySearch(element: Short, fromIndex: Int = 0, toIndex:
/**
* Returns new array which is a copy of the original array.
*/
public fun <T> Array<out T>.copyOf(): Array<out T> {
return Arrays.copyOf(this, size())
public fun <T, A: Array<out T>> A.copyOf(): A {
return Arrays.copyOf(this, size()) as A
}
/**
@@ -263,14 +263,6 @@ public fun ShortArray.copyOf(): ShortArray {
return Arrays.copyOf(this, size())
}
/**
* Returns new array which is a copy of the original array.
*/
platformName("mutableCopyOf")
public fun <T> Array<T>.copyOf(): Array<T> {
return Arrays.copyOf(this, size())
}
/**
* Returns new array which is a copy of the original array.
*/
@@ -345,8 +337,8 @@ public fun <T> Array<T>.copyOf(newSize: Int): Array<T?> {
/**
* Returns new array which is a copy of range of original array.
*/
public fun <T> Array<out T>.copyOfRange(fromIndex: Int, toIndex: Int): Array<out T> {
return Arrays.copyOfRange(this, fromIndex, toIndex)
public fun <T, A: Array<out T>> A.copyOfRange(fromIndex: Int, toIndex: Int): A {
return Arrays.copyOfRange(this, fromIndex, toIndex) as A
}
/**
@@ -405,14 +397,6 @@ public fun ShortArray.copyOfRange(fromIndex: Int, toIndex: Int): ShortArray {
return Arrays.copyOfRange(this, fromIndex, toIndex)
}
/**
* Returns new array which is a copy of range of original array.
*/
platformName("mutableCopyOfRange")
public fun <T> Array<T>.copyOfRange(fromIndex: Int, toIndex: Int): Array<T> {
return Arrays.copyOfRange(this, fromIndex, toIndex)
}
/**
* Fills original array with the provided value.
*/