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;
    }
}

```
> 
> Can anyone tell me if there is an alternative way to generate this method which works for both the primitive and non-primitive types?
> 
> 
> 

You can't do that. You can't have **one** method object that works for `foo(int)` and `foo(Integer)`. Because those would be two different methods. 

The reason why the compiler allows you to call some `foo(Integer)` with `foo(5)` is because the compiler uses boxing to turn 5 into an Integer object, to then pass that. 

Remember: the compiler decides at compile time which method will be invoked. When there are two methods of the same name with different argument types, then that is **overloading** ... and happens at compile time.

Long story short: either you have to create **two** Method objects, or **you** have to provide the necessary code to box/unbox between primitive and boxed reference types as needed!