I defined a property in the constructor of my class the following way:
class Step(val message:String = "")
When I try access to message value from Java code y get a visbility error. Why?
I defined a property in the constructor of my class the following way:
class Step(val message:String = "")
When I try access to message value from Java code y get a visbility error. Why?
The code is correct, message should be public in this case, but for some reason it is not. So, as a WO you could make it private (just drop the "val") and find a way to produce a getter for this value:
Or:
And compile:
Then create the calling Java class:
Then compile and run:
Have you tried using
getMessage()
? Maybe scala is generating the accessor.I guess that in the Java code you're trying to access the field with
step.message
. Indeed, there is such a field, and it is private. That is why you get the visibility error. When you declare 'val' fields in Scala, the compiler generates a field and accessor method. So in java you should usestep.message()
If you add the @scala.reflect.BeanProperty annontation you get "automatic" get and set methods
See http://www.scala-lang.org/docu/files/api/scala/reflect/BeanProperty.html