Hi,

please keep emails on the list. Thanks.

>     * public Object getSomeProp(int primitiveInt, int primitiveInt2);
>     * public Object getSomeProp(int primitiveInt, Number number);
>     * public Object getSomeProp(Integer… intVarargs);
>  
> In order to call getSomeProp through reflection one should pass its
> arguments as Object[]:
>  
>     Object[] arguments = new Object[] { Integer.valueOf(3),
> Integer.valueOf(7) };

The short answer is a) you cannot and b) even the compiler can get this
wrong when your methods are "too overloaded"; you sometimes need to
supply type casts as hints even in regular code. Whether this
consequence of autoboxing is a bug, a feature or a problem with the API
you are trying to call (why are there methods taking both ints and
Numbers in the first place?) is debatable.
Though AFAIK ClassMate does allow you to find all methods matching
certain types (incl. generics, which is why I posted the links), you
will still need to figure out which one to call depending on the value
types in your arguments array and a selection strategy that knows which
method to prefer. Maybe always choosing a matching method that takes
scalar values is correct; mabe it is not.
Regular reflection & autoboxing just do not mix very well.

-h
_______________________________________________
aspectj-users mailing list
aspectj-users@eclipse.org
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Reply via email to