Android Array Create emptyArray(Class kind)

Here you can find the source of emptyArray(Class kind)

Description

empty Array

Declaration

@SuppressWarnings("unchecked")
    public static <T> T[] emptyArray(Class<T> kind) 

Method Source Code

import java.lang.reflect.Array;

public class Main{
    private static final int CACHE_SIZE = 73;
    private static Object[] EMPTY = new Object[0];
    private static Object[] sCache = new Object[CACHE_SIZE];
    @SuppressWarnings("unchecked")
    public static <T> T[] emptyArray(Class<T> kind) {
        if (kind == Object.class) {
            return (T[]) EMPTY;
        }/* w  w w.j a  v  a2  s .  c om*/
        int bucket = (System.identityHashCode(kind) / 8 & 0x7FFFFFFF)
                % CACHE_SIZE;
        Object cache = sCache[bucket];
        if (cache == null || cache.getClass().getComponentType() != kind) {
            cache = Array.newInstance(kind, 0);
            sCache[bucket] = cache;
        }
        return (T[]) cache;
    }
}

Related

  1. emptyArray(Class kind)
  2. emptyArray(Class kind)
  3. nullToEmpty(Boolean[] array)
  4. nullToEmpty(Byte[] array)
  5. nullToEmpty(Character[] array)
  6. nullToEmpty(Double[] array)