這是我的代碼。我想寫7的表達式? & 10?以便編譯。斯卡拉語法糖
object Test {
trait A {
def &(other: A) = ???
}
case class B(i: Int) extends A
implicit class C(i: Int) {
def ? : A= B(i)
}
val u = 7?
val v = 10?
val w = u & v // Ok, it compiles
val z = 7? & 10? //';' expected but 10 found
val g = 7.? & 10? //';' expected but 10 found
val h = (7?) & 10? //Type mismatch. found Int(10). Required Test.A
val i = 7? & (10?) //Test.A does not take parameters (on the ?)
}
爲什麼我不能寫7? & 10?通過寫入太不同的方式,可以用6個字符來編寫此表達式嗎?
好,通過使用前綴符號用!而不是?,我可以保留我的六個字符'!7&!10' –