For example, for a single method that reads the elements of an array, how can the programmer allow either an array of objects or an array of primitives to be passed as the p
The only common supertype of Object[]
and (for example) int[]
is Object
. So the answer to your question is "No".
EDIT: Yes you could use Object
as the parameter type, but you'd need to jump through hoops (reflection or lots of typecasts) before you could use it. And you'd have to deal with the case that the thing that was passed was not an array at all.
The OP's goal is to find a single type that is better than overloading. IMO, using Object
as a claytons array type clearly does not meet this goal. It requires more complicated code, it less efficient and it is more vulnerable to unexpected runtime type errors.