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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- EF Core – Owned Entity Types & Complex Types
- TypeScript @typesTypeScript
- Trusted Types APIRustAPI
- 【譯】 Types are moving to the right
- TypeScript 之 Conditional TypesTypeScript
- TypeScript 之 Object TypesTypeScriptObject
- 譯|There Are No Reference Types in GoGo
- Typescript的interface、class和abstract classTypeScript
- TypeScript abstract 抽象類TypeScript抽象
- DataTransfer.types 屬性
- TypeScript 之 Indexed Access TypesTypeScriptIndex
- scala中的sealed
- Scala 的學習
- CNN (Convolutional Neural Networks) AbstractCNN
- static,private,final,abstract,protected
- 介面和抽象類 (abstract)抽象
- Scala
- Flink - 安裝包scala 2.12和scala 2.11的區別
- Scala的安裝以及建立Scala專案的詳細步驟
- java中的抽象類abstract怎麼使用?Java抽象
- PostgreSQL DBA(80) - Object Identifier TypesSQLObjectIDE
- Task03 : Data Types and Operators
- scala中:: , +:, :+, :::, +++的區別
- 聊聊 scala 的模式匹配模式
- Scala 簡介 [摘自 Scala程式設計 ]程式設計
- Scala學習總結(from scala for the Impatient)
- 搞懂 TypeScript 中的對映型別(Mapped Types)TypeScript型別APP
- 【譯】WebSocket協議——摘要(Abstract)Web協議
- 【Basic Abstract Algebra】Exercises of Section 1.1
- 【Basic Abstract Algebra】Exercises for Section 1.2
- 【Basic Abstract Algebra】Exercises for Section 1.4
- 【Basic Abstract Algebra】Exercises for Section 1.3
- 修飾符static和abstract
- Awesome Scala
- scala(一)
- Scala - DataFrame
- PHP中的 抽象類(abstract class)和 介面(interface)PHP抽象
- C++中的抽象基類(Abstract Base Class)C++抽象
- scala入門之編寫scala指令碼指令碼