> val foo: PartialFunction[String, Unit] = { case i: String => }
foo: PartialFunction[String,Unit] = <function1>
> val bar: PartialFunction[Int, Unit] = { case i: Int => }
bar: PartialFunction[Int,Unit] = <function1>
> foo orElse bar
PartialFunction[String with Int,Unit] = <function1>
什麼是String with Int?
。我不認爲這是可能的。什麼是「字符串與詮釋」應該是什麼意思?
> (foo orElse bar)(new String with Int)
error: illegal inheritance from final class String
(foo orElse bar)(new String with Int)
^
error: class Int needs to be a trait to be mixed in
(foo orElse bar)(new String with Int)
^
是不是應該是PartialFunction[Nothing,Unit]
?
那麼,它會* *讓你傳入null,用合適的演員。這沒有多大幫助,但它確實在技術上有用。 – 2014-11-22 17:57:41
啊,我會預料到'A with B'只有在'B'是一個特質時纔有效。 – 2014-11-22 18:02:01
我只用Scala 2.9.2測試過,因爲這是我得心應手的。不確定新版本的行爲是否有所不同。 – 2014-11-22 18:03:41