字段是否干扰了Scala动态特征的方法解析?
|
在我第一次涉足Dynamic Scala领域时,我认为我想尝试通过applyDynamic访问bean属性。
我的第一个非常粗糙的方法是
trait BeanProperties extends Dynamic {
def applyDynamic(name: String)(args: Any*) = {
if (args.length == 0)
PropertyUtils.getProperty(this, name)
else
null
}
}
以便
val bean = new JTextField(\"text\") with BeanProperties
bean.getText should equal(\"text\")
bean.text should equal(\"text\")
到目前为止,一切都很好!但是当我尝试
bean.background should equal(bean.getBackground)
编译器抱怨,而是尝试授予对名为background的字段的访问权限,而不是合成方法。
variable background in class Component cannot be accessed in javax.swing.JTextField with BeanPropertiesTest.this.BeanProperties
这是设计使然,疏忽还是计划修复的问题?
没有找到相关结果
已邀请:
2 个回复
痰嫉
冕偷淮款