스칼라에서 Java 라이브러리 (JOhm)를 사용하려고하는데 lib가 field.isAnnotationPresent(Id.class)
같은 스칼라 클래스 필드의 주석을 읽으려고 할 때 오류가 있음을 알게되었습니다. 스칼라 클래스 필드의 getAnnotations
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Id {
}
그래서 그들은 런타임에 사용할 수 있어야합니다 :
주석은 자바에 정의되어 있습니다. 그러나, 나는 시도 :
scala> import redis.clients.johm._
import redis.clients.johm._
scala> class myClass(@Id var id: java.lang.Long)
defined class myClass
scala> new myClass(id = null)
res0: myClass = [email protected]
scala> res0.getClass.getDeclaredFields
res1: Array[java.lang.reflect.Field] = Array(private java.lang.Long myClass.id)
scala> res0.getClass.getDeclaredFields.map(_.getAnnotations)
res2: Array[Array[java.lang.annotation.Annotation]] = Array(Array())
가 그럼 난 필드 (감사 ... 사용자에 유래하는) 얻을 관리하지만 난 여전히 주석에 액세스 할 수 없습니다. 나는 무엇을 잘못 했는가?
정확히 주석을 넣어하는 스칼라 말할 메타 주석이 있습니다 http://www.scala-lang.org/archives/downloads/distrib/files/nightly/docs/library/index.html# scala.annotation.meta.package – soc