According to the debugger, in the following snippet scala is boxing and unboxing the Char
argument and later boxing and unboxing the Boolean
result. Why? How to avoid that?
object Test{
def user(predicate: Char => Boolean): Boolean = {
predicate('3')
}
def main(args: Array[String]): Unit = {
var b0 = false;
for( i <- 1 to 100 ) { // warm up
b0 ||= user(Character.isDefined)
}
println(b0)
// start debugging here
val b1 = user(Character.isDigit);
println(b1)
val b2 = user(c => c == 'a');
println(b2)
}
}
As far as I know, the boxing/unboxing is expected when the involved parameters or return type is parameterized. But this is not the case. <= Wrong
Scala version 2.13.3