Scala 对象反射
如果我有以下 scala 对象:
object CustomerState {
val PENDING = "pending"
val TRIAL = "trial"
val PAYING = "paying"
val DEACTIVATED_TRIAL = "deactivated_trial"
val DEACTIVATED_PAYING = "deactivated_paying"
}
如何获取所有 val 值的列表?在这种情况下,我希望获得一个列表(“待处理”、“试用”、“正在支付”、“deactivated_trial”、“deactivated_paying”)
提前致谢, 托德
If I have the following scala object:
object CustomerState {
val PENDING = "pending"
val TRIAL = "trial"
val PAYING = "paying"
val DEACTIVATED_TRIAL = "deactivated_trial"
val DEACTIVATED_PAYING = "deactivated_paying"
}
How can I obtain a list of all the val values? In this case, I'm looking to get a List of ("pending", "trial", "paying", "deactivated_trial", "deactivated_paying")
Thanks in advance,
Todd
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
目前我认为你能做的最好的事情就是获取所有零参数方法的列表(因为这就是
val
被编译成的)并调用它们:将会有一个 Scala- 2.10 中特定的反射库,这将使事情变得更好。
At the moment I think the best you can do is to get a list of all zero-argument methods (since that's what
val
s are compiled to) and call them:There is going to be a Scala-specific reflection library in 2.10, which will make things better.
您不应该使用
Enumeration
?例子:
Shouldn't you be using an
Enumeration
?Example: