Question: I have data frame `all_vars_ready_2016`. I what to apply `table` function with `exclude=NULL` argument to that data frame in order to get frequency tables of all variables of data frame. This works:

```
mapply(table, all_vars_ready_2016)

```

I tried to add `exclude=NULL` argument in several ways but non of them succeed. What is the proper way to do that?

Answer: 
You haven't explained the purpose of this, but if I understand you correctly, `value` is an example value for a property, and you want to use it to find out the parameter type of the setter method.

But `value.getClass()` is really not suitable for this, because:

1. It can't return a primitive type.
2. It might return a subclass of the setter method's parameter type.
3. It will throw an NPE if `value` is null.

So some possible alternatives:

1. Supply the setter as a lambda function, instead of trying to hack into things with reflection. This is more performant and more flexible than using reflection.
2. If you must use reflection, supply an extra `Class` variable to your code so it knows the correct parameter type of the setter method.
3. Or, go wild, and grab the first method you see which has the setter name, no matter its type:

```
Method method;
String name = getSetMethod(key);
for (Method m : resultClass.getClass().getMethods()) {
    if (m.getName().equals(name)) {
        method = m;
        break;
    }
}

```
You will need some special handling to match these methods with primitive parameters with the corresponding boxed types.

A simple approach that might suffice is to create a mapping between the boxed and primitive types, and look for methods using both types. This is just a sketch:

```
    Map<Class<?>, Class<?>> boxedToPrimitive = new HashMap<>();
    boxedToPrimitive.put(Integer.class, Integer.TYPE);
    boxedToPrimitive.put(Long.class, Long.TYPE);
    boxedToPrimitive.put(Boolean.class, Boolean.TYPE);
    ...

    String name = getSetMethod(key);
    Method method;
    try {
        method = target.getClass().getMethod(name, val.getClass());
    } catch (NoSuchMethodException missing) {
        Class<?> alt = boxedToPrimitive.get(val.getClass());
        if (alt == null) throw missing;
        method = target.getClass().getMethod(name, alt);
    }
    method.invoke(target, value);

```