> 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