public static <T> Optional<T> cast(Class<T> targetClass, Object instance) {
        return targetClass.isInstance(instance)?
                Optional.of(targetClass.cast(instance)):
                Optional.empty();
    }
@Test(expected = IllegalArgumentException.class)
    public void cast_sample_usage() {
        Object objectToCast = "illegal";
        int result = cast(Integer.class, objectToCast).
                filter(i -> !i.equals(0)).
                orElseThrow(() -> new IllegalArgumentException("Expected non-zero integer, got " + quote(objectToCast)));
    }