public static <T> Optional<T> cast(Class<T> targetClass, Object instance) {
        return targetClass.isInstance(instance)?
                Optional.of(targetClass.cast(instance)):
                Optional.empty();
    }
Returns the casted instance if it is assignment-compatible with targetClass,
or empty otherwise.

@see Class#isInstance(Object)
vespajlib/src/main/java/com/yahoo/reflection/Casting.java