I tested this code :
Collection l = new ArrayList<Object>();
l.add(5);
l.add(2);
l.add(6);
Integer[] a=l.toArray(new Integer[0]);//this requires casting to Integer[]
and also look at this code:
Collection<Object> l = new ArrayList<Object>();
l.add(5);
l.add(2);
l.add(6);
Integer[] a=l.toArray(new Integer[0]);//this doesn't require casting to Integer[]
first question is
Why first requires casting but second doesn't?
second question is
the size of array doesn't matter any role why we don't pass just class name or by other way?What is the reason for making api like this?