> 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]
?
最佳答案
What is String with Int?
它是一种交叉类型。 IE。这种类型的值必须是
Int
和一个 String
同时。I don't think that's even possible.
是的,这是一种无人居住的类型。但是,一般情况下,如果替换
Int
和 String
某些类型 A
和 B
, 你会得到 PartialFunction[A with B, Unit]
并且编译器对此没有特殊情况。
关于scala - "String with Int"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27080523/