我之前问过这个问题:Combine a PartialFunction with a regular function
然后意识到,我实际上并没有问对它。所以,这是另一次尝试。
如果我这样做:
val foo = PartialFunction[Int, String] { case 1 => "foo" }
val bar = foo orElse { case x => x.toString }它不能编译:error: missing parameter type for expanded function The argument types of an anonymous function must be fully known. (SLS 8.5) Expected type was: PartialFunction[?,?]
但这很好用:
val x: Seq[String] = List(1,2,3).collect { case x => x.toString }问题是有什么不同?在这两种情况下,参数的类型是相同的:PartialFunction[Int, String]。传入的值完全相同。为什么一种情况可以工作,而另一种情况不行?
https://stackoverflow.com/questions/38359522
复制相似问题