Created
January 5, 2013 06:01
-
-
Save anonymous/4460049 to your computer and use it in GitHub Desktop.
Removing warts from Scala by making them ambiguous
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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