我通过以下方式在类的构造函数中定义了一个属性:
class Step(val message:String = "")
当我尝试访问时message从 Java 代码中获取可见性错误的值。为什么?
如果添加 @scala.reflect.BeanProperty 注释,您将获得“自动”get and set methods
See http://www.scala-lang.org/docu/files/api/scala/reflect/BeanProperty.html http://www.scala-lang.org/docu/files/api/scala/reflect/BeanProperty.html
scala> class Step(@scala.reflect.BeanProperty val message:String )
defined class Step
scala> val s = new Step("asdf")
s: Step = Step@71e13a2c
scala> s.message
res6: String = asdf
scala> s.getMessage
res10: String = asdf
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)