我嘗試這樣做:排序就地陣列,斯卡拉
implicit class ArrayExtensions[A](a: Array[A]) {
/**
* Sort a slice [from, until) of this array
*/
def sort(from: Int, until: Int)(implicit cmp: Ordering[A]) = java.util.Arrays.sort(a, from, until, cmp)
}
但是,我認爲我打a bug in the compiler:
[error] found : Array[A]
[error] required: Array[? with Object]
[error] Note: A >: ? with Object, but class Array is invariant in type T.
[error] You may wish to investigate a wildcard type such as `_ >: ? with Object`. (SLS 3.2.10)
[error] def sort(from: Int, until: Int)(implicit cmp: Ordering[A]) = java.util.Arrays.sort(a, from, until, cmp)
如何解決這個問題?
我認爲JVM可以是一個標籤。我相信Java不應該是一個標籤。 – mubeen
直接調用java.util.Arrays.sort會產生什麼問題? – kostya
@kostya:我剛剛發佈了編譯錯誤,當我調用java.util.Arrays' – pathikrit