2

I have some statically compiled trait:

trait SomeTrait {
  def printMessage()
}

And I have some string:

val a = """class SomeClass extends SomeTrait{override def printMessage() = {println("hello")}}"""

How can I dynamically load class from file?

Something like this, for example:

var b : SomeTrait = ClassLoader[SomeTrait](a)
b.pringMessage()

I saw some class like Interpreter in previous versions of Scala, but didn't find it in Scala 2.10.2. I newbie in Scala, so I may wrong.

EECOLOR
  • 11,184
  • 3
  • 41
  • 75
Lunigorn
  • 1,340
  • 3
  • 19
  • 27
  • From what I've understood: you want an eval function in Scala. You can take a look at [this discussion](http://stackoverflow.com/questions/1183645/eval-in-scala) from 2009 about it. – AlexBergeron Sep 09 '13 at 20:51
  • 1
    For testing purposes I used this: http://stackoverflow.com/a/15323481/596816 – EECOLOR Sep 09 '13 at 20:52
  • You want to use the recent support for reflection/using the compiler, and @EECOLOR is using exactly that API. This API did not exist in 2009. – Blaisorblade Oct 28 '13 at 01:23

1 Answers1

1

you might want to check twitter-util eval.

Mortimer
  • 2,966
  • 23
  • 24