dynamically create class in scala, should I use interpreter?

Posted by Phil on Stack Overflow See other posts from Stack Overflow or by Phil
Published on 2010-05-02T01:55:31Z Indexed on 2010/05/02 1:57 UTC
Read the original article Hit count: 520

Filed under:
|
|
|

Hi,

I want to create a class at run-time in Scala. For now, just consider a simple case where I want to make the equivalent of a java bean with some attributes, I only know these attributes at run time.

How can I create the scala class? I am willing to create from scala source file if there is a way to compile it and load it at run time, I may want to as I sometimes have some complex function I want to add to the class. How can I do it?

I worry that the scala interpreter which I read about is sandboxing the interpreted code that it loads so that it won't be available to the general application hosting the interpreter? If this is the case, then I wouldn't be able to use the dynamically loaded scala class.

Anyway, the question is, how can I dynamically create a scala class at run time and use it in my application, best case is to load it from a scala source file at run time, something like interpreterSource("file.scala") and its loaded into my current runtime, second best case is some creation by calling methods ie. createClass(...) to create it at runtime.

Thanks, Phil

© Stack Overflow or respective owner

Related posts about scala

Related posts about interpreter