如何将 Scala 枚举作为参数传递?
我的枚举如下
object Market extends Enumeration {
type Market = Value
val ASX = Value("ASX")
val LSE = Value("LSE")
}
,然后
class MyClass (currentMarket: Market) {
}
结果如下:
未找到:类型 Market
My Enumeration is as follows
object Market extends Enumeration {
type Market = Value
val ASX = Value("ASX")
val LSE = Value("LSE")
}
then
class MyClass (currentMarket: Market) {
}
Results in the following:
not found: type Market
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须导入枚举:
不过,更常见的是仅编写
Market.Value
来引用枚举类型。这还可以为您保存
Market
中的类型别名。You have to import the enumeration:
It's more common, though, to just write
Market.Value
to refer to the enumeration type.That also saves you the type alias in
Market
.