Just map it over and work with Option
Option(javaList).map(asScalaBuffer).getOrElse(ArrayBuffer.empty)
Update
If you still want a factory for null
arrays/lists, then you can simulate it by a "constructor method" (basing on Rex Kerr's answer):
def ArrayBuffer[T](jl: JavaList[T]) = if (jl == null) ArrayBuffer.empty[T] else asScalaBuffer(jl)
and then use ArrayBuffer(null.asInstanceOf[JavaList[String])
it looks just like Option.apply
:
def apply[A](x: A): Option[A] = if (x == null) None else Some(x)