Skip to content

Instantly share code, notes, and snippets.

@tkawachi
Created May 27, 2015 14:05
Show Gist options
  • Save tkawachi/18f73497a409574c056d to your computer and use it in GitHub Desktop.
Save tkawachi/18f73497a409574c056d to your computer and use it in GitHub Desktop.
case class A(i: Int)
case class B(i: Int)
case class C(i: Int)
class ImplicitTest {
object Implicits {
implicit val ia = A(1)
}
implicit def a2b(implicit a: A): B = new B(a.i)
implicit def b2c(implicit b: B): C = new C(b.i)
// import Implicits._ // -- (1)
// import ImplicitTest.ImplicitsInCompanion._ // -- (2)
// implicit val ial = A(1) // -- (3)
// (1) のみ -- コンパイルできる
// (2) のみ -- コンパイルできない
// (3) のみ -- コンパイルできる
// (1) と (3) -- コンパイルできない
// なにもなし -- コンパイルできない
implicitly[C]
}
object ImplicitTest {
object ImplicitsInCompanion {
implicit val iac = A(2)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment