Cast { private Cast() {} private  Cast(); static Optional<T> cast(Object object, Class<T> clazz); static T castOrFail(Object object, Class<T> clazz);  }
@Test void cast() { assertThrows(NullPointerException.class, () -> Cast.cast("value", null)); final Optional<String> nullOptional = Cast.cast(null, String.class); assertFalse(nullOptional.isPresent()); final Optional<String> illegalCastOptional = Cast.cast(1, String.class); assertFalse(illegalCastOptional.isPresent()); final Optional<Number> successfulOptional = Cast.cast(1L, Number.class); assertTrue(successfulOptional.isPresent()); assertEquals(1, successfulOptional.get().intValue()); }