score:0
the comment about scala.tools.reflect.toolbox
put me on the right track and i ended up being able to answer my own question. something like this is what i was looking for:
import scala.reflect.runtime._
import scala.reflect.runtime.universe._
import scala.tools.reflect.toolbox
object main extends app {
val cm = universe.runtimemirror(getclass.getclassloader)
val toolbox = cm.mktoolbox()
val f = toolbox.eval(toolbox.parse("""(x:double) => x*x"""))
f match {
case f1:scala.function1[double, any] =>
println(f1(4.4))
case _ =>
throw new exception("expected a function1[double,any] but got something else")
}
}
Source: stackoverflow.com
Related Query
- Compile Scala Object using NSC
- Using Scala reflection to compile and load object
- How do I call a Scala Object method using reflection?
- Scala compile server error when using nailgun
- Serializing a scala object into a JSon String using lift-json
- How to mock a function within Scala object using Mockito?
- Scala capture object reference while still using extractors
- What is the fastest way to compile Scala files using maven?
- How to add a json object in to a json array using scala play?
- Scala dependency injection when using case class/companion object pattern
- How to access all public members of an object recursively using Scala reflection?
- Compile error when using a companion object of a case class as a type parameter
- How to select a object field for map value in Scala using groupby
- Using Scala class defined in package object from Java
- reduceByKey using Scala object as key
- Using ListView from Scala 2.9.2 with Java 7 gives compile error
- "illegal cyclic reference involving object InterfaceAudience" when using Scala 2.11 reflection
- Using vals from scala package object in java
- scala specialization - using object instead of class causes slowdown?
- Serialize to object using scala mongo driver?
- Using private[this] on an object member in Scala
- Using Java locale in Scala complains: object is not a value
- "Error:scalac: Error: object VolatileFloatRef does not have a member create" when using Scala 2.11.8 SDK
- Using Spark Scala in EMR to get S3 Object size (folder, files)
- Return Scala object to C++ using JNI
- Sorting multiple fields in an object using scala sortWith function
- How to Compile Apache Spark with Scala 2.11.1 using SBT?
- Error: value is not a member of object using Scala on the shell
- convert scala object to json using json4s
- Using scala object inside java?
More Query from same tag
- Spark DataFrame Parallelism
- Cannot resolve overloaded method 'createDataFrame'
- Spark (Scala): How to turn an Array[Row] into either a DataSet[Row] or a DataFrame?
- case class and traits
- How to display project-specific message at the beginning of an sbt shell session?
- OpenCV Get the Shape of the Matrix
- how to pivot Spark dataframe table?
- java.lang.NoSuchMethodError: shapeless.DefaultSymbolicLabelling$.instance(Lshapeless/HList;)Lshapeless/DefaultSymbolicLabelling;
- Actor/message-passing within threaded Game "event loop"
- Play: How to implement vermongo with ReactiveMongo
- neo4j with Flink and Scala
- How to succinctly map Map to Map
- Scala - unit test setup (use access modifier qualifiers?)
- Trying to save Spark SQL Dataframes always leads in empty directories
- Option converter for XStream in Scala
- Slick 3.0.0 Warning when using Update
- Perfomance using orientdb graph api vs sql query
- Spark Scala 2.10 tuple limit
- importing a library that contains a same "namespaces" as Scala Option
- How can I partition a RDD respecting order?
- Type inference of foldLeft with a covariant empty seed
- How do I "left join" in Scala Array[Array[String]]?
- Play 2.1 Unit Test With Slick and Postgres
- Debug exceptions in AWT queue thread
- Scala Spark setting schema duplicates columns
- Pattern matching syntax in Scala/Unfiltered
- Scala general performances and code optimization
- Spark -Scala Nested array DF - How to update value based on condition without changing structure?
- Scala Cast object to another type
- Scala compiler build error JComboBox type parameters