learning scala pattern matching 03

Posted lianghong881018

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了learning scala pattern matching 03相关的知识,希望对你有一定的参考价值。

 code: 

package com.aura.scala.day01

object patternMatching03 
  //当不同类型对象需要调用不同方法时,仅匹配类型的模式非常有用。
  def goIDLE(device : Device) =  device match 
    case p: Phone => p.screenOff
    case c:Computer => c.screenSaverOn
  

abstract class Device

case class Phone(model:String) extends  Device
  def screenOff = "Turning screen off"

 

以上是关于learning scala pattern matching 03的主要内容,如果未能解决你的问题,请参考以下文章

Scala: Reader Pattern

Scala: Cake Pattern

learning scala PartialFunction

Scala之模式匹配(Patterns Matching)

learning scala read from file

Beginning Scala study note Pattern Matching