Created
July 18, 2011 17:43
-
-
Save leifwickland/1090136 to your computer and use it in GitHub Desktop.
Recommended way of pimping Scala types (rather than using implicit conversions) according to Jorge's laws in http://dl.dropbox.com/u/1679797/Scalathon/CanBeConfusing.pdf
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
class ByteArrayWrapper(bytes: Array[Byte]) { | |
def fromUtf8: String = { | |
"Converted to String." | |
} | |
} | |
object ByteArrayWrapper { | |
implicit def makeByteArrayWrapper(bytes: Array[Byte]): ByteArrayWrapper = new ByteArrayWrapper(bytes) | |
} | |
object byteImplicit extends App { | |
import ByteArrayWrapper._ | |
println("start") | |
val b = Array[Byte](32,30) | |
println("b = " + b.fromUtf8) | |
println("done") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment