A multipurpose field in an Object of type ObjectHolder contains an Object obj. obj might store a wrapped primitive or an array of primitives. How can we compare two objs if they are arrays? A simplified example:
import java.util.Arrays;
public class ObjectHolder {
public Object obj;
public static void main(String[] args) {
ObjectHolder oh1 = new ObjectHolder();
oh1.obj = new int[]{ 3, 4, 5 };
ObjectHolder oh2 = new ObjectHolder();
oh2.obj = new int[]{ 3, 4, 5 };
if (oh1.obj.getClass().isArray() && oh2.obj.getClass().isArray()) {
System.out.println("We know both objects are arrays.");
// System.out.println(Arrays.equals(oh1.obj, oh2.obj));
}
}
}
The commented-out line causes the compile to break.
Note- the array can be of any primitive type (or String), so simply casting it to int[] is not a convenient general solution.