ClassCastException when casting object Array to Long array

前端 未结 2 1862
无人共我
无人共我 2021-01-13 12:00

I get this exception when i try to cast an Object array to a Long array.

Exception in thread \"main\" java.lang.ClassCastException: [Ljava.lang.O

2条回答
  •  余生分开走
    2021-01-13 12:12

    change

    returnValues = (Long[]) hotelRooms.keySet().toArray();
    

    to

    returnValues = hotelRooms.keySet().toArray(new Long[hotelRooms.size()]);
    

    and let me know if it works :-)

提交回复
热议问题