Is it possible to construct subj? Something like:
trait THasArray[T]
{
val ARRAY_SIZE = 8
val array = Array.fill[T](ARRAY_SIZE)(null)
}
doesn't work well - compiler complains about 'null', which I need to have. I know about Option, though the question is, whether this is possible with plain arrays.
Thanks.
EDIT:
Thanks both of you, guys. I've already found that trick with passing class tag as an implicit parameter.
Though, I've re-formulated my original issue a bit. I needed that array to be initialized only once, and never change. So here's my solution which doesn't require implicit val type tag, but instead uses init function to do the trick
trait THasArray[T >: Null]
{
private var table: Seq[T] = null
protected def init(elems: (Int, T)*)(implicit manifest: Manifest[T]) =
{
val size = (elems foldLeft 0)(_ max _._1)
val array = Array.fill[T](size + 1)(null)
elems foreach { x => array(x._1) = x._2 }
table = array
}
}