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
change
returnValues = (Long[]) hotelRooms.keySet().toArray();
to
returnValues = hotelRooms.keySet().toArray(new Long[hotelRooms.size()]);
and let me know if it works :-)
It's because Object[] Set.toArray()
returns an object array. You can't downcast the array to a more specific type. Use <T> T[]Set.toArray(T[] a)
instead. If the generic type method didn't exist you'd have to loop through each of the Objects in the return object array and cast each individually into a new Long array.