如何将 Scala 枚举作为参数传递?

发布于 2024-11-24 02:53:10 字数 267 浏览 2 评论 0原文

我的枚举如下

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遮了一弯 2024-12-01 02:53:10

您必须导入枚举:

import Market._

不过,更常见的是仅编写 Market.Value 来引用枚举类型。
这还可以为您保存 Market 中的类型别名。

You have to import the enumeration:

import Market._

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.

留一抹残留的笑 2024-12-01 02:53:10
import Market

class MyClass (currentMarket: Market.Market) {
}
import Market

class MyClass (currentMarket: Market.Market) {
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文