Document unchecked suppression.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1450421 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
65eea73e74
commit
680979f72e
|
@ -457,11 +457,12 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
|
||||||
* a supertype of the runtime type of the elements in this list
|
* a supertype of the runtime type of the elements in this list
|
||||||
* @throws NullPointerException if the specified array is null
|
* @throws NullPointerException if the specified array is null
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public <T> T[] toArray(T[] array) {
|
public <T> T[] toArray(T[] array) {
|
||||||
final int size = size();
|
final int size = size();
|
||||||
if (array.length < size) {
|
if (array.length < size) {
|
||||||
array = (T[]) Array.newInstance(array.getClass().getComponentType(), size);
|
@SuppressWarnings("unchecked") // safe as both are of type T
|
||||||
|
final T[] unchecked = (T[]) Array.newInstance(array.getClass().getComponentType(), size);
|
||||||
|
array = unchecked;
|
||||||
}
|
}
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
@ -469,7 +470,10 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
final E current = it.next();
|
final E current = it.next();
|
||||||
for (int index = getCount(current); index > 0; index--) {
|
for (int index = getCount(current); index > 0; index--) {
|
||||||
array[i++] = (T) current;
|
// unsafe, will throw ArrayStoreException if types are not compatible, see javadoc
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
final T unchecked = (T) current;
|
||||||
|
array[i++] = unchecked;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (i < array.length) {
|
while (i < array.length) {
|
||||||
|
|
Loading…
Reference in New Issue