I have a code that a AnyVal type data f should be converted into Float/Double depending on the input parameter.
if (n == 4) {
if (f.asInstanceOf[Float].isNaN) None
else Some(f)
} else {
if (f.asInstanceOf[Double].isNaN) None
else Some(f)
}
I tried to use variable to get this code, but I have an error.
val t = if (n == 4) classOf[Float] else classOf[Double]
if (f.asInstanceOf[t].isNaN) None
else Some(f)

What might be wrong?