I have an object that needs printing, but I get it cast as "Object". The following is the only way I know how to return a String representation of this:
is there a better way? did I forget anything?
Liam Morley
lmorley@wpi.edu
"light the deep, and bring silence to the world.
light the world, and bring depth to the silence."
Code:
private String getValueAsArrayString() {
assert value.getClass().isArray();
if (value instanceof boolean[])
return Arrays.toString((boolean[]) value);
else if (value instanceof byte[])
return Arrays.toString((byte[]) value);
else if (value instanceof char[])
return Arrays.toString((char[]) value);
else if (value instanceof double[])
return Arrays.toString((double[]) value);
else if (value instanceof float[])
return Arrays.toString((float[]) value);
else if (value instanceof int[])
return Arrays.toString((int[]) value);
else if (value instanceof long[])
return Arrays.toString((long[]) value);
else if (value instanceof short[])
return Arrays.toString((short[]) value);
else if (value instanceof Object[])
return Arrays.deepToString((Object[]) value);
else
throw new AssertionError("unknown type: " + value.getClass());
}
Liam Morley
lmorley@wpi.edu
"light the deep, and bring silence to the world.
light the world, and bring depth to the silence."