小编dar*_*ack的帖子

How does the Scala compiler perform implicit conversion?

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)

scala scalac scala-compiler scala-quasiquotes

7
推荐指数
1
解决办法
182
查看次数

在 SBT 中导入 scala.tools.reflect.ToolBox 时出错

我正在尝试在 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)

scala sbt

5
推荐指数
1
解决办法
1989
查看次数

标签 统计

scala ×2

sbt ×1

scala-compiler ×1

scala-quasiquotes ×1

scalac ×1