public static int sizeOf(Class<?> cls) {
        if(cls == boolean.class) return 1;
        if(cls == byte.class)    return 1;
        if(cls == char.class)    return 2;
        if(cls == short.class)   return 2;
        if(cls == int.class)     return 4;
        if(cls == long.class)    return 8;
        if(cls == float.class)   return 4;
        if(cls == double.class)  return 8;
        throw new IllegalArgumentException(
                "Cannot request size of non-primitive type");
    }