enums - Retrieving Scala enumeration constants by name -


i retreiving scala enumeration constants name.

dmitriy yefremov propose solution scala 2.10 (@see http://yefremov.net/blog/scala-enum-by-name/)

the code crash

private def factorymethodsymbol(enumtype: type): methodsymbol = {   enumtype.member(newtermname("withname")).asmethod // scala.scalareflectionexception: <none> not method } 

i update code use scala 2.11. idea ?

you can existing api, don't need workarounds:

def constantbyname[t <: enumeration](enum: t, key: string): option[t#value] = {   enum.values.find(_.tostring == key) } 

it works because .values gives list[enum#value] , can matching.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -