메시지를 감싸고 랩핑 한 메시지를 기록하고 싶습니다. 나는 더 나은 솔루션이 있는지 궁금클래스를 가져 오는 방법 _ : 모두
result = any match {
case x:AnyRef => x.getClass
case _:Double => classOf[Double]
case _:Float => classOf[Float]
case _:Long => classOf[Long]
case _:Int => classOf[Int]
case _:Short => classOf[Short]
case _:Byte => classOf[Byte]
case _:Unit => classOf[Unit]
case _:Boolean=> classOf[Boolean]
case _:Char => classOf[Char]
}
: 내가 찾을 수
val any :Any = msg.wrappedMsg
var result :Class[_] = null
유일한 해결책은 모든 것을 일치한다? 다음이 방법은 :(
result = any.getClass //error
// type mismatch; found : Any required: ?{val getClass: ?}
// Note: Any is not implicitly converted to AnyRef.
// You can safely pattern match x: AnyRef or cast x.asInstanceOf[AnyRef] to do so.
result = any match {
case x:AnyRef => x.getClass
case x:AnyVal => /*voodoo to get class*/ null // error
}
//type AnyVal cannot be used in a type pattern or isInstanceOf