码迷,mamicode.com
首页 > 其他好文 > 详细

Scala抽象类型

时间:2019-01-07 21:36:00      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:import   from   rri   int   分享图片   fromfile   bst   http   tty   

 1 package big.data.analyse.scala
 2 
 3 import scala.io.{BufferedSource, Source}
 4 
 5 /**
 6   * 抽象类型
 7   * Created by zhen on 2019/1/6.
 8   */
 9 trait Reader{
10   type url <: java.io.Serializable
11   type content
12   def reader(fileUrl : url) : content
13 }
14 class FileReader extends Reader{
15   type url = String
16   type content = BufferedSource
17   override def reader(fileUrl : url) = Source.fromFile(fileUrl)
18 }
19 object AbstractType {
20   def main(args: Array[String]) {
21     val fileReader = new FileReader
22     val source = fileReader.reader("C:/Users/zhen/.spyder-py3/发布模块/setup.py")
23     for(line <- source.getLines()){
24       println(line)
25     }
26   }
27 }

结果:

技术分享图片

 

Scala抽象类型

标签:import   from   rri   int   分享图片   fromfile   bst   http   tty   

原文地址:https://www.cnblogs.com/yszd/p/10234808.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!