package object


當一個套件內存在公用的變數或是方法函數,可以放在package object中,
通常會放入型別的別名以及隱式轉換,以下是型別別名的範例

named package.scala

package object collectionmutable {

type ListBuffer[A] = collection.mutable.ListBuffer[A]
 val ListBuffer = collection.mutable.ListBuffer
 // more mutable collection implement
}

import collectionmutable._

ListBuffer(1,2)

Reference

Comments