Skip to content

Instantly share code, notes, and snippets.

@nowelium
Created July 29, 2010 01:10
Show Gist options
  • Save nowelium/496933 to your computer and use it in GitHub Desktop.
Save nowelium/496933 to your computer and use it in GitHub Desktop.
package hoge
import scala.tools.nsc.Interpreter
import scala.tools.nsc.InterpreterResults.Result
import scala.tools.nsc.Settings
class User(id:Int, name:String) {
def id():Int = { id }
def name():String = { name }
override def toString():String = {
"id: " + id + " name: " + name
}
}
object A {
def main(args: Array[String]): Unit = {
val s = new Settings(Console.println)
s.classpath.value = System.getProperty("java.class.path");
val itpr = new Interpreter(s)
itpr.bind("user", "hoge.User", new User(1, "hoge"));
val r:Result = itpr.interpret("""
Console.println("hello");
Console.println(user)
Console.println("id =>" + user.id);
Console.println("name => " + user.name);
""")
println("result => " + r);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment