sta*_*ker 5 puzzle syntax obfuscation scala
在他的scala编程(第5章第5.9节第93页)中,奥德斯基提到了这个表达" bills !*&^%~ code!
"
在同一页面的脚注中:
"到现在你应该能够弄清楚,鉴于此代码,Scala编译器会
调用 (bills.!*&^%~(code)).!()."
这对我来说有点神秘,有人能解释一下这里发生了什么吗?
奥德斯基的意思是说有可能拥有这样的有效代码.例如,下面的代码:
class BadCode(whose: String, source: String) {
def ! = println(whose+", what the hell do you mean by '"+source+"'???")
}
class Programmer(who: String) {
def !*&^%~(source: String) = new BadCode(who, source)
}
val bills = new Programmer("Bill")
val code = "def !*&^%~(source: String) = new BadCode(who, source)"
bills !*&^%~ code!
Run Code Online (Sandbox Code Playgroud)
只需将其复制并粘贴到REPL上即可.