ArrayList of objects to array of object, does not work
Hello,
I have a short problem in transforming an ArrayList full of User 's to an array full of User 's.
It seems Java isn't supporting this directly, example code:
function User[] getUsers()
{
...
ArrayList<User> userArrayList =new ArrayList<User>;
...
//fill list with User 's
...
User[] users = (User[]) userArrayList.toArray();
return users;
}
This code gives a class cast exception, cannot cast Object[] to User[].
Why is this?
When you manually iterate the arrayList and cast all objects to the User type in the array it will work, but it is more code + kinda takes out the use for a toArray() function.
Is there something I am doing wrong or is it just not possible in java?

