views:

94

answers:

1

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.

+2  A: 

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

Arjan Blokzijl
I saw that posting too, but unfortunately that won't work... the reflection occurs in the Properties parent class, which is written in the java language, and I can't change that source code.
I'm affraid there's not much you can do then, Scala does not emit public fields in the generated bytecode, so the way the Properties class does reflection, will not work for your Scala code.
Arjan Blokzijl