I do not understand why Scala complains about a type error in the following example:
def GetRanges(RangeString1: String): Array[String] = {
val GetOneRange = "\\d+\\-\\d+".r;
var AllRanges = new Array[String](0);
if (!f_stringNullEmpty(RangeString1)) {
GetOneRange.findAllIn(RangeString1).matchData.foreach(
m => AllRanges = AllRanges ++ Array[String](m.group(0)) // Explicit casting to Array[String]
)
}
return scala.util.Sorting.quickSort(AllRanges);
}
the error I receive is:
notebook:38: error: type mismatch;
found : Unit
required: Array[String]
return scala.util.Sorting.quickSort(AllRanges);
^
Apparently, iterating through the regex results and adding them to the array, causes a type change. But why? Or did I miss something more fundamental?
Note: I understand that the if statement returns a type Unit, because no else was specified. But I can;t see that that would affect the type of my array.