class PacketSomething(var number: Int, var infos: String)
class PacketSomethingBuilder[P <: PacketSomething] {
private var number: Int = _
private var infos: String = _
def withNumber(n: Int): Builder[P with Number] {
number=n
this.asInstanceOf[Builder[P with Number]]
}
def withInfos(s: String): Builder[P with Infos] {
infos=s
this.asInstanceOf[Builder[P with Infos]]
}
def build()(implicit evidence: P =:= Complete) {
new PacketSomething(number, infos)
}
object PacketSomethingBuilder {
sealed trait Number
sealed trait Infos
type Complete = PacketSomething with Number with Infos
}
We could also provide a way to construct a NiolBuffer directly, if the performance benefit is worth it.
Example of how this could be done :
We could also provide a way to construct a NiolBuffer directly, if the performance benefit is worth it.