@SuppressWarnings("unchecked")
    public <T> T[] toArray(final T[] a)
    {
        final Class<?> componentType = a.getClass().getComponentType();
        if (!componentType.isAssignableFrom(Integer.class))
        {
            throw new ArrayStoreException("cannot store Integers in array of type " + componentType);
        }

        @DoNotSub final int size = size();
        final T[] arrayCopy = a.length >= size ? a : (T[])Array.newInstance(componentType, size);
        copyValues(arrayCopy);

        return arrayCopy;
    }
@Test
    @SuppressWarnings("SuspiciousToArrayCall")
    void toArrayThrowsArrayStoreExceptionForWrongType()
    {
        assertThrows(ArrayStoreException.class, () -> testSet.toArray(new String[1]));
    }