标签:style blog http color os 使用 ar div 2014
此文章记录日常学到的scala知识点,以便日后查询。
记录一:unapplay()方法在模式匹配中的使用 (2014-09-24 13:21:51)
1 object StockService{ 2 def process(input:String){ 3 input match{ 4 case Symbol() => println("Yes," + input) 5 case _ => println("Invalid input " + input) 6 } 7 } 8 } 9 object Symbol{ 10 def unapply(symbol: String):Boolean = symbol == "GooG" || symbol == "IBM" 11 } 12 object test extends App{ 13 StockService process "GooG" 14 StockService process "IBM" 15 StockService process "ERR" 16 }
运算结果如下:
Unapply()方法使用:http://openhome.cc/Gossip/Scala/ApplyUnApply.html
标签:style blog http color os 使用 ar div 2014
原文地址:http://www.cnblogs.com/horde/p/3990483.html