mardi 27 juin 2023

Scala: Convert Iterable[Any] to the actual type of its content

I want to be able cast a generic iterable to the actual type of its contents, but I don't know the type at compile time. Is there a way to have a function like this?

def castIterable[IN, OUT](iterable: Iterable[IN]): Iterable[OUT] = {
  iterable.asInstanceOf[Iterable[ figureOutContentType(...) ]]
}




Aucun commentaire:

Enregistrer un commentaire