Class Optional


  • public class Optional
    extends java.lang.Object
    Represents an optional value that may or may not be present.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object get()
      Returns the contained value, or throws an exception if empty.
      void ifPresent​(LambdaExpression le)
      If a value is present, invokes the given lambda with the value.
      java.lang.Object orElse​(java.lang.Object other)
      Returns the contained value, or the given default value if empty.
      java.lang.Object orElseGet​(java.lang.Object le)
      Returns the contained value, or the result of evaluating the given lambda if empty.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • get

        public java.lang.Object get()
                             throws ELException
        Returns the contained value, or throws an exception if empty.
        Returns:
        The contained value
        Throws:
        ELException - if the value is not present
      • ifPresent

        public void ifPresent​(LambdaExpression le)
        If a value is present, invokes the given lambda with the value.
        Parameters:
        le - The lambda expression to invoke
      • orElse

        public java.lang.Object orElse​(java.lang.Object other)
        Returns the contained value, or the given default value if empty.
        Parameters:
        other - The default value
        Returns:
        The contained value or the default
      • orElseGet

        public java.lang.Object orElseGet​(java.lang.Object le)
        Returns the contained value, or the result of evaluating the given lambda if empty.
        Parameters:
        le - The lambda expression or already-evaluated value
        Returns:
        The contained value or the result of the lambda