You did not say what params
is. It looks like it might be a Map[String, X]
with some type X
. params.getOrElse(key, someLong)
will considered to have the best common supertype of X
and Long
which happens to be Any
, according to the error message, and which has no toLong method. As your default value happens to be Long already, and so don't need to be converted, I guess there is a toLong
method on X
.
If it is so, then you should convert the value retrieved from params
to Long
(when there is such a value), before providing the default value. That would be :
params.get("key").map(_.toLong).getOrElse(defaultValue)