Scala的Abstract Types
點選(此處)摺疊或開啟
-
trait Reader{
-
type In <: java.io.Serializable //限定型別上界
-
type Contents //抽象型別
-
def read(in: In): Contents
-
}
-
class FileReader extends Reader {
-
type In = String //具體例項化抽象型別
-
type Contents = BufferedSource
-
override def read(name: In) = Source.fromFile(name)
-
}
-
object Abstract_Types {
-
-
def main(args: Array[String]) {
-
val fileReader = new FileReader
-
val content = fileReader.read("E:\\test.txt")
-
for (line <- content.getLines){
-
println(line)
-
}
-
}
-
- }
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28912557/viewspace-1985281/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Scala的Infix Type與Self Types
- java abstractJava
- abstract 的 interface ,如何理解?
- EF Core – Owned Entity Types & Complex Types
- TypeScript @typesTypeScript
- stock Types
- c# abstractC#
- 【Scala篇】--Scala中的函式函式
- Types of Locks (340)
- Scala學習(五)---Scala中的類
- Typescript的interface、class和abstract classTypeScript
- TypeScript abstract 抽象類TypeScript抽象
- abstract類和介面
- java基礎:abstractJava
- Abstract Factory + Template = BuilderUI
- 【Scala】Scala之ObjectObject
- 譯|There Are No Reference Types in GoGo
- TypeScript 之 Object TypesTypeScriptObject
- Two Types of Error in JAVAErrorJava
- Understanding Service Types
- Types of SAP Support PackagesPackage
- types of undo segments(ZT)
- Behind RabbitMQ Exchange TypesMQ
- Trusted Types APIRustAPI
- 有趣的 Scala 語言: 簡潔的 Scala 語法
- 【Scala】Scala之TraitsAI
- 介面和抽象類 (abstract)抽象
- C# interface abstract classC#
- C#基礎——abstractC#
- Scala 的學習
- Scala的泛型泛型
- Scala的HelloWorld程式
- Scala的繼承繼承
- Scala的applyAPP
- 【Scala】Scala之Packaging and ImportsImport
- Scala學習(六)---Scala物件物件
- DataTransfer.types 屬性
- TypeScript 之 Indexed Access TypesTypeScriptIndex