Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala enumeration to int

Tags:

scala

Is there a way to identify that a given object is an Enumeration value?

x.isInstanceOf[Enumeration.$Value] doesn't seem to work, and from what I understand of path-dependent types, shouldn't.

I'd like to write a function that given any Enumeration value, returns its id. Alternatively, an implicit that converts the Enumeration to Int would also be great.

like image 462
Pandora Lee Avatar asked Jul 09 '11 05:07

Pandora Lee


1 Answers

x.isInstanceOf[Enumeration#Value] works for me. From the specification, Section 3.2.2 "Type Projection".

like image 112
Francois G Avatar answered Oct 25 '22 03:10

Francois G