learning scala sealed class

package com.aura.scala.day01

object sealedClassed {
  def findPlaceToSit(piece: Furniture) = piece match {
    case a: Couch => "Lie on the couch"
    case b: Chair => "Sit on the chair"
  }

}

//sealed定义密封类
sealed abstract class  Furniture
case class Couch() extends Furniture
case class Chair() extends Furniture

 

posted @ 2019-07-10 13:17  嵌入式实操  阅读(89)  评论(0编辑  收藏  举报