Skip to content

Instantly share code, notes, and snippets.

Created January 5, 2013 06:01
Show Gist options
  • Save anonymous/4460049 to your computer and use it in GitHub Desktop.
Save anonymous/4460049 to your computer and use it in GitHub Desktop.
Removing warts from Scala by making them ambiguous
import language.implicitConversions
class AmbiguousStringAdd {
def +(b: String) = ???
}
implicit def amb1anyref2stringadd(a: AnyRef) = new AmbiguousStringAdd
implicit def amb2anyref2stringadd(a: AnyRef) = new AmbiguousStringAdd
class A {}
// Won't compile!
// println(new A + "ASDF")
// Sadly, this still works when implicit on Any, due to compiler magic
println(1 + "ASDF")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment