Canonical way for empty Array in Scala?

后端 未结 4 1331
名媛妹妹
名媛妹妹 2020-12-28 11:37

What is the canonical way to get an empty array in Scala? new Array[String](0) is too verbose.

4条回答
  •  一个人的身影
    2020-12-28 12:09

    If the array type is one of the primitives, you can use the shortcuts from scala.Array.

    For example for a byte array it would be:

    val arr = Array.emptyByteArray
    

    This is useful when the type cannot be inferred and you want to remain less verbose.

提交回复
热议问题