The toInt
method in StringLike
doesn't take any arguments, and can only parse in decimal. So to parse binary, hex etc we need to resort to Java's Integer#parseInt(String s, int radix)
.
In an attempt to remedy this state of affairs, I tried the following
implicit def strToToIntable(s: String) = new {
def toInt(n: Int) = Integer.parseInt(s, n)
}
However,
"101".toInt(2)
causes the REPL compiler to "crash spectacularly" and doesn't work in compiled code either.
Is there some restriction on overloading existing methods using the "enrich my library" pattern?