I'm totally new to Scala. Here I have tried to assign a empty array to a variable, it was successful. But when I tried to append an integer element to the variable an error occured as below:
var c=Array()
c: Array[Nothing] = Array()
scala> c=Array(1)
<console>:8: error: type mismatch;
found : Int(1)
required: Nothing
c=Array(1)
^
What is the reason for this?
When you do
var c = Array(), Scala computes the type asArray[Nothing]and therefore you can't reassign it with aArray[Int]. What you can do is:or