On 02/26/2013 07:57 AM, Simone Tripodi wrote: > Hi Thomas, > >> + @SuppressWarnings("unchecked") >> public <T> T[] toArray(T[] array) { >> final int size = size(); >> if (array.length < size) { >> - // This is safe, both are type T >> array = (T[]) >> Array.newInstance(array.getClass().getComponentType(), size); >> } >> >> @@ -466,7 +469,6 @@ public abstract class AbstractMapBag<E> >> while (it.hasNext()) { >> final E current = it.next(); >> for (int index = getCount(current); index > 0; index--) { >> - // TODO this is unsafe >> array[i++] = (T) current; >> } >> } >> > > it is a good practice here commenting why the unchecked warning can be > suppressed - it will definitively help also future maintainers :)
it is not safe, and it will throw an ArrayStoreException in this case, which is documented in the throws clause. This is the same behavior as with all java.util collections. Thomas --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org