Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Welcome to Scala version 2.11.4 (OpenJDK 64-Bit Server VM, Java 1.6.0_27).
Type in expressions to have them evaluated.
Type :help for more information.
scala> case class Foo[T](name: String)
defined class Foo
scala> implicit val stringFoo = Foo[String]("String")
stringFoo: Foo[String] = Foo(String)
scala> implicit val intFoo = Foo[Int]("Int")
intFoo: Foo[Int] = Foo(Int)
scala> case class Bar[T]()(implicit foo: Foo[T]) { println(foo.name) }
defined class Bar
scala> val bar = Bar()
<console>:13: error: ambiguous implicit values:
both value stringFoo of type => Foo[String]
and value intFoo of type => Foo[Int]
match expected type Foo[T]
val bar = Bar()
^
scala> val bar: Bar[Int] = Bar()
Int
bar: Bar[Int] = Bar()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment