scala.js - How does scala.Enumeration.nextName get the identifier text? -


scala.enumerator.nextname , .nextnameornull read:

/** string use name next created value. */ protected var nextname: iterator[string] = _  private def nextnameornull =   if (nextname != null && nextname.hasnext) nextname.next() else null 

nextnameornull subsequently called name use item being created in enumeration.

how code achieve this?

when copy-paste simple example:

class mybaseclass extends serializable {   /** string use name next created value. */   protected var nextname: iterator[string] = _    private def nextnameornull =     if (nextname != null && nextname.hasnext) nextname.next() else null    protected final def value(): val = val(nextnameornull)    case class val(name:string) }  object myobject extends mybaseclass {   val myvalue = value    println("hello myobject, myvalue: " + myvalue) } 

it prints: hello myobject, myvalue: val(null) instead of hoped val(myvalue)

what need add make work?

in scala jvm, enumeration uses reflection name of val value assigned if nextnameornull returns null.

in scala.js, not have luxury (no reflection support). therefore, scala.js compiler special cases scala.enumeration, code uses can work.

if want implement mdethod knows name of val assigned to, have @ sbt's project macro. scala's enumerations have been implemented way starting 2.10, older.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -