This is because you return a Int Value in the true-branch. Scala behaves with those primitive datatypes just like java (the classes are transformed into primitives through the compiler). So the return type of your if could be either a char or a int (12 is a integer, because number literals are always integers). Since a char could not hold every int, the compiler "casts" your char to a int.
If you would cast 12
to a char like this:
val achar = 'a'
if (b > 12) 12.asInstanceOf[Char] else achar
It would return a char.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…