scala 中的 Groovy 的 classX.metaClass.getProperty
scala 中是否有与 Groovy 出色的 SomeClass.metaClass.getProperty 函数等效的东西?这对于制作特定领域的语言非常有帮助。例如,我可以说: val x = SomeClass(); x.任意属性名称
,而不是x.get("任意属性名称")
或x("任意属性名称")
。
Is there anything equivalent to Groovy's remarkable SomeClass.metaClass.getProperty function in scala? This would be very helpful in making domain specific languages. For example, I could then say: val x = SomeClass(); x.arbitraryPropertyName
rather than x.get("arbitraryPropertyName")
or x("arbitraryPropertyName")
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的描述,此功能听起来像 Scala 的
Dynamic
。从Scaladoc,也就是说,如果您的类扩展了
Dynamic
,则x.atoryPropertyName
形式的调用将被转换为x.applyDynamic("atoryPropertyName")
,当然,您还可以定义applyDynamic
的行为。From your description, this feature sounds like Scala's
Dynamic
. From the Scaladoc,That is, if your class extends
Dynamic
, then calls of the formx.arbitraryPropertyName
get translated tox.applyDynamic("arbitraryPropertyName")
, and of course you get to define the behavior ofapplyDynamic
.