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
We have to create parameterized constructor for this enum class. Why? Because as we know that enum class's object can't be create explicitly so for initializing we use parameterized constructor. And the constructor cannot be the public or protected it must have private or default modifiers.
In Scala, there is no enum keyword unlike Java or C. Scala provides an Enumeration class which we can extend in order to create our enumerations. Every Enumeration constant represents an object of type Enumeration. Enumeration values are defined as val members of the evaluation.
enums are technically descendants of Enum class. So, if you want to use only Enum's standard methods in your method (such as values()), pass the parameter like this: static void printEnumValue(Enum generalInformation) See, that the only thing you have to change is the capital letter E.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With