I have a custom class, A, and I have defined some operations within the class as follows:
def +(that: A) = ...
def -(that: A) = ...
def *(that: A) = ...
def +(that: Double) = ...
def -(that: Double) = ...
def *(that: Double) = ...
Run Code Online (Sandbox Code Playgroud)
In order to have something like 2.0 + x make sense when x is of type A, I have defined the following implicit class:
object A {
implicit class Ops (lhs: …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 SBT 中编译以下代码作为子项目的一部分。
package bitstream.compiler
package eval
import scala.reflect.runtime.universe._
import scala.reflect.runtime.currentMirror
import scala.tools.reflect.ToolBox
// Based on code from:
// https://gist.github.com/xuwei-k/9ba39fe22f120cb098f4
object Eval {
def apply[A](tree: Tree): A = {
val toolbox = currentMirror.mkToolBox()
toolbox.eval(tree).asInstanceOf[A]
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的build.sbt:
lazy val commonSettings = Seq(
organization := "com.bitbucket.example-project",
scalaVersion := "2.12.6"
)
lazy val root = (project in file("."))
.settings(
commonSettings,
version := "0.1.0-SNAPSHOT",
name := "example-project"
)
lazy val plugin = (project in file("plugin"))
.settings(
commonSettings,
scalacOptions += "-J-Xss256m",
name …Run Code Online (Sandbox Code Playgroud)