(스칼라에서 자바 리플렉션을 사용하는 맥락에서) 자바 클래스 [_]에서 스칼라 패턴 매칭을 사용하려하지만 예기치 않은 오류가 발생했습니다. 이런 일이 왜 다음은 경우 jlong를클래스 [_] 유형의 패턴 일치?
def foo[T](paramType: Class[_]): Unit = {
val jInteger = classOf[java.lang.Integer]
val jLong = classOf[java.lang.Long]
paramType match {
case jInteger => println("int")
case jLong => println("long")
}
}
어떤 아이디어가있는 라인의 "도달 할 수없는 코드를"제공? 코드에서
scala> def foo[T](paramType: Class[_]): Unit = {
| val jInteger = classOf[java.lang.Integer]
| val jLong = classOf[java.lang.Long]
| paramType match {
| case `jInteger` => println("int")
| case `jLong` => println("long")
| }
| }
foo: [T](paramType: Class[_])Unit
scala> foo(classOf[java.lang.Integer])
int
첫 번째 패턴의 jInteger
새로운 가변이다 :
역 따옴표 괜찮을거야 것은 나보다 더 나은 솔루션입니다 : 최고 – JaimeJorge
! 많은 고마워, 트래비스. – alphageek