capint
8/10/2016 - 1:58 PM

Java >> Guava >> Optional

Java >> Guava >> Optional

public Optional<URI> getURI(String id_p) {
  if (registryEntry.getKey().getId().equals(id_p)) {
    // Return an Optional containing the real value
    return Optional.<URI> of(registryEntry.getValue());
  }
  // Return an absent Optional
  return Optional.<URI> absent();
}
 //Optional.fromNullable - allows passed parameter to be null.
 Optional<Integer> a = Optional.fromNullable(value1);
Used facilitate the code to handle values as available or not available instead of checking null values