I bumped into a code snippet and not able to make sense out of it. The snippet is:
implicit val dummyVisit = Visit("", 1L, 1, 1, 1, 1L)
implicit val dummyOrder = Order("", 1L, 1, 1, 1, 1L)
def process[T](events : Array[T])(implicit t: T):Unit = {
println(t)
if(!events.isEmpty)
t match {
case r: Order => processOrder(events.asInstanceOf[Array[Order]])
case r: Visit => processVisit(events.asInstanceOf[Array[Visit]]);
}
}
def processOrder(arr: Array[Order]): Unit = { println(arr.size) }
def processVisit(arr: Array[Visit]): Unit = { println(arr.size) }
The implicit
variable t
, requires the dummyVisit
& dummyOrder
to exist.
Question:
Is this a right way of using
implicit parameter
?Is there a better way for get the class-type of
T
, without using implicit parameter?