我在Scala中理解Array组合时遇到了一些麻烦.
以下工作正常:
scala> Array('0', '1', '2') ++ Array('A', 'B', 'C')
res0: Array[Char] = Array(0, 1, 2, A, B, C)
Run Code Online (Sandbox Code Playgroud)
但是这个没有:
scala> ('0' to '9').toArray ++ ('A' to 'Z').toArray
<console>:8: error: polymorphic expression cannot be instantiated to expected type;
found : [B >: Char]Array[B]
required: scala.collection.GenTraversableOnce[?]
('0' to '9').toArray ++ ('A' to 'Z').toArray
^
Run Code Online (Sandbox Code Playgroud)
而且,以下似乎有效:
scala> ('0' to '9').toArray
res1: Array[Char] = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
scala> ('A' to 'Z').toArray
res2: Array[Char] = Array(A, B, …Run Code Online (Sandbox Code Playgroud)