Created
March 25, 2009 19:31
-
-
Save dlwh/85658 to your computer and use it in GitHub Desktop.
This file contains 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
implicit class RichString(s: String) extends RandomAccessSeq[Char] { | |
def apply(x: Int) = s.charAt(x); | |
// whatever | |
var foo = 3; | |
def twiddle = { foo += 1; foo } | |
} | |
yields | |
class RichString(s: String) extends RandomAccessSeq[Char] { | |
def apply(x: Int) = RichString.static$.apply(s,x); | |
// no forwarding for vars, or methods that reference them | |
var foo = 3; | |
def twiddle = { foo += 1; foo } | |
} | |
object RichString { | |
implicit def conversion(s: String) = new RichString(s); | |
private object static$ { | |
def apply(s: String, x: Int) = s.charAt(i); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment