If you only want to handle object arrays (not primitive arrays) you can just cast to Object[]
, due to array variance:
if (value instanceof Object[]) {
String text = Arrays.deepToString((Object[]) value);
...
}
For primitive arrays you couldn't call deepToString
anyway, of course.
Sample code to demonstrate array variance:
public class Test {
public static void main(String[] args) {
Object x = new String[] { "Hello", "there" };
Object[] array = (String[]) x;
// Prints "class [Ljava.lang.String;"
System.out.println(array.getClass());
}
}
As you can see, the array
value still refers to a string array - but a String[]
reference can be assigned to an Object[]
variable.