I am trying to create an array of Char using another array of Int's size. Code doesn't compile:
object Main {
def main(args: Array[String]): Unit = {
val mapping = Map(1 -> "ABC", 2 -> "DEF")
val a = mapping.keySet.toArray
val c = Array[Char](a.length)
}
}
The compiler throws an error: "type mismatch; found : Int required: Char"
when I change the code above to:
val c = Array[Char](2) // no compiler error
Looks like the compiler is interpreting my input not as a size param but instead thinking it's a Char such as an initial element of the Char array
Since in java this code would compile without a problem I was wondering what's the proper way of using another array length as a size param to init a different array in Scala?