scala中List的泛型分析以及::类和Nil对象

学习了scala中List的泛型分析以及::类和Nil对象List是对scala的类型系统的一个非常好的使用,进一步巩固List的知识对于理解scala的类型系统是非常有价值的。本讲主要分析了List的泛型、::类和Nil对象。 List有两个非常重要的子类,一个是::,一个是Nil,这两个子类都是case classNil表示一个空的列表,而::表达的是一个非空的列表。

例子如下:

 case object Nil extends List[Nothing]{ 

 

          override def isEmpty = true

          override def head : Nothing = throw new NoSuchElementException("tail of empty list")

          override def tail : List[Nothing] = throw new UnsupportedOperationException("tail of empty list")

          override def equals(that Any) = that match{ 

               case that1 : scala.collection.GenSeq[_] => that1.isEmpty

               case _ => false

          }

      }

 

 王家林亲授《DT大数据梦工厂》大数据实战视频“Scala深入浅出实战经典”视频、音频和PPT下载!第80讲:Scala的List的泛型分析以及::类和Nil对象
腾讯微云:http://url.cn/bzzNPZ
百度云盘:http://pan.baidu.com/s/1gdnjT3l
360云盘:http://yunpan.cn/cd3whmTfPFGY5  访问密码 b6af

posted on 2015-08-08 08:24  l_time  阅读(1585)  评论(1)    收藏  举报

导航