I have the following method:
public static int arraySum(Object obj) {
}
The method should return the sum of all elements in obj; a precondition for this method is that obj be an Integer array of any dimension, i.e. Integer, Integer[], Integer[][], so on.
In order to write the body of the method arraySum(), I'm using a foreach loop and recursion; however, for the foreach loop I need to know which type the elements of obj are. Is there a way to find out the type (i.e. Integer, Integer[], etc.) of obj?
EDIT: This is for an assignment for my CS course. I don't want to simply ask how to write the method, that's why I'm asking such a specific question.
objcould have any number of dimensions, meaning lots and lots of if statements