public K[] toArray()
{
K[] result = (K[])new Object[this.size()];
int index = 0;
for(K k : this)
result[index++] = k;
return result;
}
This code does not seem to work, it will through out an exception:
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to ...
Could someone tell me how I can create an array with a generic type? Thanks.