给出下面的代码:斯卡拉提取 - 跳过未使用的参数
abstract class MyTuple
...
case class MySeptet(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int, g: Int) extends MyTuple
case class MyOctet(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int, g: Int, h: Int) extends MyTuple
...
使用时产生的提取,是有可能跳过其余参数,假设他们未使用的?
例如我不想写大量的下划线在下面的代码片段:
case MyOctet(a, b, _, _, _, _, _, _) => ... // uses only a and b
我建议咬咬牙写下划线,或(甚至更好)试图打破下来你的情况类成小块。 –
目前这是不可能的,但有建议允许与命名参数和默认参数进行匹配(请参阅[这里](https://issues.scala-lang.org/browse/SI-5323)和[here](https:/ /issues.scala-lang.org/browse/SI-6524)),这将允许一个简单的语法。 – wingedsubmariner
相关:http://stackoverflow.com/questions/3474125/how-to-pattern-match-large-scala-case-classes –