Class Result<T>

  • Type Parameters:
    T - type of object the function should have returned

    public class Result<T>
    extends java.lang.Object
    Instances of this class can be used when a function may encounter an error and wants to display the error message but you want to manually display it.
    • Constructor Summary

      Constructors 
      Constructor Description
      Result​(T value, java.lang.String error)
      Instantiates Result and sets either the value or error.
      Only one of both can be set, error is preferred to prevent unexpected behavior.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      T get()  
      java.lang.String getError()  
      boolean wasSuccessful()  
      • Methods inherited from class java.lang.Object

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

      • Result

        public Result​(T value,
                      java.lang.String error)
        Instantiates Result and sets either the value or error.
        Only one of both can be set, error is preferred to prevent unexpected behavior.
        Parameters:
        value - if successful or null
        error - if failed or null
        Throws:
        java.lang.IllegalArgumentException - in case both parameters are set to null
    • Method Detail

      • wasSuccessful

        public boolean wasSuccessful()
        Returns:
        whether retrieving the result was successful
      • get

        public T get()
        Returns:
        the result
      • getError

        public java.lang.String getError()
        Returns:
        the error