Collection.toArray() java.lang.ClassCastException

前端 未结 4 845
既然无缘
既然无缘 2021-02-05 08:23
import java.util.HashMap;
import java.util.Map;


public class Main
{
    public static void main(String[] args)
    {
        Map map=new HashMap&l         


        
4条回答
  •  星月不相逢
    2021-02-05 08:51

    toArray() returns an Object[] [and not any object derived from Object[]]. Each element in this array is of type Class, but the array itself is not of type Class[]

    You should cast each element in the array to Class instead of trying to cast the array, or use Collection.toArray(T[]) to avoid casting.

提交回复
热议问题