Java – using enumerations in Scala

I have Scala style enumerations

object SomeObject {

  final object SomeEnum extends Enumeration {
    type SomeEnum = Value
    val val1,val2,val3 = Value
  }

How can I:

1) Can the valueof method be called to get the value through string representation?

val possibleVal3 = SomeObject.someEnum.valueOf("val3")

2) Call the ordinal simulation of Java:

val a = SomeObject.someEnum.val2
a.ordinal

Obviously, there is no such method in someenum

Solution

> withName():

val possibleVal3 = SomeObject.someEnum.withName("val3")

> id:

val ordinal = SomeObject.someEnum.val2.id

You can also see:

> Enumeration

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>