object case04 {
def matchType(value:Any):Unit = {
value match {
case x:Int => println(s"${x} 是Int")
case x:Double => println(s"${x} 是Double")
case _ => println("未知")
}
}
def main(args: Array[String]): Unit = {
matchType(1)
matchType(1.1)
case class Circle(radius: Double) {}
case class Rectang(width: Double, height: Double) {}
def getArea(shape: Any): Double = {
shape match {
case Circle(radius) => math.pi * radius * radius
case Rectangle(width,height) => width * height
case _ => 0.0
}
}
def main(args: Array[String]): Unit = {
val circle = Circle(2.0)