Replacing case class inheritance with extractors preserving exhaustiveness checks in Scala
问题 I have a simple class hierarchy that represents a graph-like structure with several distinct types of vertexes implemented using case classes: sealed trait Node sealed abstract case class Vertex extends Node case class Arc extends Node case class VertexType1 (val a:Int) extends Vertex case class VertexType2 (val b:Int) extends Vertex This allows me to write match blocks like this: def test (x: Node) = x match { case _ : Arc => "got arc" case _ : Vertex => "got vertex" } or like this: def test