import java.util.HashMap;
import java.util.Map;
public class Main
{
public static void main(String[] args)
{
Map map=new HashMap&l
Change:
Class[] classes = (Class[]) map.values().toArray();
To:
Class[] classes = map.values().toArray(new Class[0]);
This gives information on which type of array to convert the Collection
to. Otherwise, it returns an array of type Object
(and that cannot be cast to an Class[]
).
Quoted from the API documentation for Collection.toArray(T[] a):
Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array. ...
Note thattoArray(new Object[0])
is identical in function totoArray()
.