public static <T> Optional<T> cast(Object object, Class<T> clazz) {
        requireNonNull(clazz);
        if (object == null) {
            return Optional.empty();
        }
        if (clazz.isAssignableFrom(object.getClass())) {
            final T result = clazz.cast(object);
            return Optional.of(result);
        }
        return Optional.empty();
    }
Casts and returns the provided object if it is assignable from the given
class, otherwise returns an Optional.empty().

@param <T> the type to return
@param object to cast
@param clazz to cast to
@return An Optional of the casted element or Optional.empty()
runtime-parent/runtime-core/src/main/java/com/speedment/runtime/core/internal/util/Cast.java