Scala: abstract type pattern A is unchecked since it is eliminated by erasure
问题 I am writing the function that can catch exceptions of the certain type only. def myFunc[A <: Exception]() { try { println("Hello world") // or something else } catch { case a: A => // warning: abstract type pattern A is unchecked since it is eliminated by erasure } } What is the corrent way to bypass jvm type erasure in such case? 回答1: You could use ClassTag like in this answer. But I'd prefer this approach: def myFunc(recover: PartialFunction[Throwable, Unit]): Unit = { try { println("Hello