top | item 2179226

Scala's upcoming dynamic capabilities

28 points| DanielRibeiro | 15 years ago |squirrelsewer.blogspot.com | reply

9 comments

order
[+] rit|15 years ago|reply
Last week I spent a little bit of time trying to figure out how the Dynamic trait works and what its good for.

I managed to do a quick and dirty 5 minute mockup of a "Callable" Map that lets you invoke keys as method names:

https://gist.github.com/797513

[+] metageek|15 years ago|reply

  def invokeDynamic(name: String)(args: Any*) = {
    println("Invoke Dynamic: (name = %s)(args: %s)".format(name, args))
    get(name.asInstanceOf[String])
  }
Why do you need the asInstanceOf(), when name is already declared to be a String?

Sorry if this is obvious; I don't know Scala (I've glanced at it, but the 2.8 compiler is too slow on my laptop--as in, about one line per minute).