在切换到Scala 2.10之后,我收到了大量的警告:
结构类型成员方法的
反射访问...应通过使隐含值language.reflectiveCalls可见来启用
什么意思?
发布于 2012-11-12 13:42:55
该警告实际上告诉您在文档中查找解释的位置:
Test.scala:9: warning: reflective access of structural type member method y should be enabled
by making the implicit value language.reflectiveCalls visible.
This can be achieved by adding the import clause 'import scala.language.reflectiveCalls'
or by setting the compiler option -language:reflectiveCalls.
See the Scala docs for value scala.language.reflectiveCalls for a discussion
why the feature should be explicitly enabled.
Referenced Scaladoc entry (确保单击左侧的|>箭头以展开documentation条目)。
发布于 2017-12-18 05:59:32
来自Scala文档:
为什么要控制它?反射并不是在所有平台上都可用。流行的工具,如ProGuard,在处理它时遇到了问题。即使在反射可用的地方,反射分派也会导致令人惊讶的性能下降。
考虑一下使用匿名子类的代码:
class Student(val id:Int)
val specialStudent = new Student(0) {
val greeting = "I am a special student with id " + id // Warning: id can be obfuscated
}
发布于 2021-01-23 02:22:31
我在使用一个函数将Option[Double or Long]
除以100时遇到了以下警告:
def safeDivideBy100[T <: AnyVal { def toDouble: Double }](number: Option[T]): Option[Double] =
number match {
case None => None
case Some(x) => Some(x.toDouble / 100)
}
修复它只需要添加到文件的顶部:
import scala.language.reflectiveCalls
https://stackoverflow.com/questions/13337976
复制相似问题