第54讲:Scala中复合类型实战详解
2015-09-10 23:28
218 查看
今天学习了scala的复合类型的内容,让我们通过实战来看看代码:
trait Compound_Type1
trait Compound_Type2
class Compound_Type extends Compound_Type1 with Compound_Type2
object test54 {
def compound_Type(x:Compound_Type1 with Compound_Type2) = {println ("Compound_Type test")}
def main(args:Array[String]){
compound_Type(new Compound_Type1 with Compound_Type2)
object compound_Type_oject extends Compound_Type1 with Compound_Type2
compound_Type(compound_Type_oject)
type compound_Type_Alias = Compound_Type1 with Compound_Type2
def compound_Type_Local(x:compound_Type_Alias)=println("Compound_Type test2")
val compound_Type_Class = new Compound_Type
compound_Type_Local(compound_Type_Class)
type Scala = Compound_Type1 with Compound_Type2 {def init():Unit}
}
}
首先,定义了两个特质Compound_Type1和Compound_Type2,然后定义了类Compound_Type继承自它们。
然后我们定义一个compound_Type方法,它只允许传入Compound_Type1 with Compound_Type2类型的对像,这种类型,就叫做复合类型。
当我们新定义一个对像时并调用该方法时,便会打印Compound_Type test
当然,我们也可以使用type方法来给复合类型定义一个别名,如:
type compound_Type_Alias = Compound_Type1 with Compound_Type2
def compound_Type_Local(x:compound_Type_Alias)=println("Compound_Type test2")
分享下更多的scala资源吧:
百度云盘:http://pan.baidu.com/s/1gd7133t
微云云盘:http://share.weiyun.com/047efd6cc76d6c0cb21605cfaa88c416
360云盘: http://yunpan.cn/cQN9gvcKXe26M (提取码:13cd)
信息来源于 DT大数据梦工厂微信公众账号:DT_Spark
关注微信账号,获取更多关于scala学习内容
trait Compound_Type1
trait Compound_Type2
class Compound_Type extends Compound_Type1 with Compound_Type2
object test54 {
def compound_Type(x:Compound_Type1 with Compound_Type2) = {println ("Compound_Type test")}
def main(args:Array[String]){
compound_Type(new Compound_Type1 with Compound_Type2)
object compound_Type_oject extends Compound_Type1 with Compound_Type2
compound_Type(compound_Type_oject)
type compound_Type_Alias = Compound_Type1 with Compound_Type2
def compound_Type_Local(x:compound_Type_Alias)=println("Compound_Type test2")
val compound_Type_Class = new Compound_Type
compound_Type_Local(compound_Type_Class)
type Scala = Compound_Type1 with Compound_Type2 {def init():Unit}
}
}
首先,定义了两个特质Compound_Type1和Compound_Type2,然后定义了类Compound_Type继承自它们。
然后我们定义一个compound_Type方法,它只允许传入Compound_Type1 with Compound_Type2类型的对像,这种类型,就叫做复合类型。
当我们新定义一个对像时并调用该方法时,便会打印Compound_Type test
当然,我们也可以使用type方法来给复合类型定义一个别名,如:
type compound_Type_Alias = Compound_Type1 with Compound_Type2
def compound_Type_Local(x:compound_Type_Alias)=println("Compound_Type test2")
分享下更多的scala资源吧:
百度云盘:http://pan.baidu.com/s/1gd7133t
微云云盘:http://share.weiyun.com/047efd6cc76d6c0cb21605cfaa88c416
360云盘: http://yunpan.cn/cQN9gvcKXe26M (提取码:13cd)
信息来源于 DT大数据梦工厂微信公众账号:DT_Spark
关注微信账号,获取更多关于scala学习内容
相关文章推荐
- linux 之df 和du
- 解决No “rule to make target `../Database/images/login.png', needed by `debug/qrc_image.cpp'. Stop.”
- Andrew Ng机器学习课程9
- 定时器.倒计时
- java之常量池
- C++数据结构之链式队列(Linked Queue)
- .net 的一个分词系统(jieba中文分词的.NET版本:jieba.NET)
- C语言位运算详解
- C语言位运算详解
- 蒜头爬楼梯
- hdu 1866 几个矩形面积的和 ***
- EF基础概念篇1
- 免费学习编程的 12 个地方
- android自定义布局中的平滑移动
- 一次快速排序错误引发的思考(1)
- Android Studio出现Gradle '×××' project refresh failed 解决办法
- MySQL 基础操作语法
- 软件研发:公司内部技术考试——答题方法
- Intellij IDEA + Spring MVC + Maven 环境搭建
- [渗透测试] john the ripper