### Question:
SafeCast { public static byte[] toByteArray(Object o, byte[] def) { if (!(o instanceof byte[])) { return def; } return (byte[]) o; }  static long toLong(Object o, long def); static int toInt(Object o, int def); static byte toByte(Object o, byte def); static float toFloat(Object o, float def); static byte[] toByteArray(Object o, byte[] def); static short[] toShortArray(Object o, short[] def); static int[] toIntArray(Object o, int[] def); static String toString(Object o, String def); static T toGeneric(Object o, U def, Class<T> clazz);  }### Answer:
@Test public void testByteArray() { byte[] array = new byte[10]; byte[] backup = new byte[10]; assertTrue("Unable to process valid cast", SafeCast.toByteArray(array, backup) == array); assertTrue("Default did not work (wrong type)", SafeCast.toByteArray(new Integer(22), backup) == backup); assertTrue("Default did not work (null)", SafeCast.toByteArray(null, backup) == backup); }