About 170,000 results
Open links in new tab
  1. java - Uses for Optional - Stack Overflow

    May 4, 2014 · Having been using Java 8 now for 6+ months or so, I'm pretty happy with the new API changes. One area I'm still not confident in is when to use Optional. I seem to swing …

  2. Para que serve o Optional do Java 8? Como usar?

    Apr 22, 2020 · Qual a utilidade do Optional do Java 8? Como se usa esse recurso? As melhores respostas que achei no site foram essas... Qual a diferença entre os métodos orElse() e …

  3. Why use Optional.of over Optional.ofNullable? - Stack Overflow

    Jul 29, 2015 · There are three static methods in java.util.Optional. Optional#empty() Optional#of(T value) Optional#ofNullable(T value) The pair is not of and ofNullable, but of and empty. This is …

  4. serialization - Why java.util.Optional is not Serializable, how to ...

    The Enum class is Serializable so there is no problem to serialize object with enums. The other case is where class has fields of java.util.Optional class. In this case the following exception is t...

  5. Optional vs. null. What is the purpose of Optional in Java 8?

    Feb 26, 2015 · In Java 8 you can return an Optional instead of a null. Java 8 documentation says that an Optional is "A container object which may or may not contain a non-null value. If a …

  6. Object cannot be converted to string when using Optional class in …

    Aug 20, 2018 · I have the following code trying to use the Optional class: import java.util.Optional; // one class needs to have a main() method public class HelloWorld { public String …

  7. Java 8 method references: provide a Supplier capable of supplying …

    I'd like to use java.util.Optional.orElseThrow() with an Exception type that asks for a constructor parameter. Something like this: .orElseThrow(MyException::new(someArgument)) // obviously …

  8. Incompatible types - Found void java.util.Optional

    Incompatible types - Found void java.util.Optional Asked 4 years, 10 months ago Modified 4 years, 10 months ago Viewed 6k times

  9. java - Optional.get () versus overloaded Optional.orElseThrow ...

    How can one avoid explicitly throwing an Exception while trying to get the value from an Optional or while making use of Optional.get? Currently, this is possibly safeguarded with the API …

  10. option type - java.util.Objects vs Optional which is preferable ...

    The java.util.Objects class was extended with a number of new methods Objects#requireNonNullElse respectively Objects#requireNonNullElseGet() in Java-9. Both will …