trait Buffering { this: FileInputStream => val b = new BufferedInputStream(this) override def read(ab: Array[Byte]): Int = { b.read(ab) } } val b = new FileInputStream("c:/ObjectTest.obj") with Buffering val ab = new Array[Byte](10) while(b.read(ab) != -1) { ab.foreach(a => print(a.toChar)) }
特质->self type:this
最新推荐文章于 2021-07-14 17:45:16 发布