Created
January 29, 2009 19:09
-
-
Save p3t0r/54679 to your computer and use it in GitHub Desktop.
overloading a unary operator in scala
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 MyString(string:String){ | |
var value = string | |
def unary_- = new MyString(new StringBuilder(value).reverse.toString) | |
override def toString = value | |
} | |
val myString = new MyString("abcd") | |
println(myString) // prints "abcd" | |
println(-myString) // prints "dcba" |
mariohuizar
commented
Apr 16, 2018
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment