I need to create a temporary Array[T | Null]
where T
is a type parameter with AnyRef
as upper bound.
Given the arrays implementation will use an Array[AnyRef]
after erasure for whatever T
is, why should I relay on a ClassTag
?
def method[T <: AnyRef](elements: Iterable[T])(using ctTorNull: ClassTag[T | Null]): T =
val array = elements.toArray[T | Null]
???
}
Is there a way to achieve the same without using ClassTag
nor asInstanceOf
in scala 3.4?