In my Java code I often use the very handy method(Class... args)
varargs. As far as I know, they allow you to pass any amount of Class
objects or an array of Class[]
. Since I also often use the Java collection classes, I am frustrated by the lack of compatibility between both. As a result, I end up doing collection.toArray()
, but that has some type safety issues.
So now for the question: why doesn't Java allow instances of Iterable<T>
as vararg arguments, as long as the generic type fits the T...
type of the vararg? Doesn't everyone use lists, sets, etc. all the time? Is there an easy, type-safe way to provide the conversion from collection to vararg?