lundi 17 février 2020

How to get the class type of the contents of an Iterable in scala?

Say I have a method like this:

def getClassFromIterable(iterable: Iterable[Any]): Class[_] = {
  iterable.head.getClass
}

This will get the class of the top of the list, but will fail if the list is empty.
How can I get the class of a passed list that has zero or more elements?





Aucun commentaire:

Enregistrer un commentaire