Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scala equivalent of java public field

In java, I have a class like this:

public class MyClass extends Properties {
    public StringProperty prop1 = new StringProperty(this, "default value for prop1");  
    public StringProperty prop2 = new StringProperty(this, "prop2 default val");
}//MyClass

The parent class "Properties" uses reflection to look for all public fields in itself, and fills the variables with values as needed.

How would I extend Properties in scala? Using var prop1:StringProperty ... does not work, I'm assuming due to how scala converts private fields to get... set... type methods.

like image 477
user85116 Avatar asked Jun 23 '10 14:06

user85116


1 Answers

Scala marks the field as private, but generates accessor methods to set and get its value. If you want to use reflection to do this, you can do this the way that is described: here

like image 135
Arjan Blokzijl Avatar answered Oct 10 '22 09:10

Arjan Blokzijl