标签:screens xtend end nsa oid 不同方法 object case pre
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
标签:screens xtend end nsa oid 不同方法 object case pre
原文地址:https://www.cnblogs.com/lianghong881018/p/11163274.html