code: public static boolean isOptional(final Type type) {
          if (OPTIONAL_CLASS == null) {
              return false;
          }
  
          if (!(type instanceof ParameterizedType)) {
              // Either this is no Optional, or it's a raw optional which is useless for us anyway...
              return false;
          }
  
          return OPTIONAL_CLASS.equals(((ParameterizedType) type).getRawType());
      }
docs: Checks if given type is java.util.Optional with a generic type parameter.
  
  @param type
  @return true if and only if type is a parameterized Optional