@SuppressWarnings("unchecked") public <R>Optional<R> select(Class<R> clazz){
  Objects.requireNonNull(clazz);
  if (!isPresent())   return empty();
  return (Optional<R>)Optional.ofNullable(clazz.isInstance(value) ? value : null);
}

@ SuppressWarnings ( "unchecked" ) public < R > Optional < R > select ( Class < R > clazz ) { Objects . requireNonNull ( clazz ) ; if ( ! isPresent ( ) ) return empty ( ) ; return ( Optional < R > ) Optional . ofNullable ( clazz . isInstance ( value ) ? value : null ) ; }
keeps inner value only if is present and instance of given class .
