通过反射设置 javafx 属性
Setting javafx Property via reflection
正在尝试通过反射(ORM 案例)将值设置为可观察 属性。
public class TestVAO
{
private Property<Long> id = new SimpleObjectProperty<>();
}
此代码无效。正确的做法是什么?
if (field.getType().isAssignableFrom(Property.class))
{
field.setAccessible(true);
field.set(obj, value);
}
这成功了。这是正确的做法吗?
@SuppressWarnings("unchecked")
final Property<Object> property = (Property<Object>)field.get(obj);
property.setValue(value);
正在尝试通过反射(ORM 案例)将值设置为可观察 属性。
public class TestVAO
{
private Property<Long> id = new SimpleObjectProperty<>();
}
此代码无效。正确的做法是什么?
if (field.getType().isAssignableFrom(Property.class))
{
field.setAccessible(true);
field.set(obj, value);
}
这成功了。这是正确的做法吗?
@SuppressWarnings("unchecked")
final Property<Object> property = (Property<Object>)field.get(obj);
property.setValue(value);