Class Unit

  • All Implemented Interfaces:
    java.io.Serializable

    public final class Unit
    extends java.lang.Object
    implements java.io.Serializable
    Represents the type scala.Unit.
    The usage of Unit is for situations where one returns types such as Try or Future that are not meant to hold a value.
    E.g.
     
     Try<Unit> deleteSynchronous(String id)
     Future<Unit> deleteAsynchronous(String id)
     
     
    The example illustrates deleting something but the only thing we care of is if the operation was successful.
    This becomes very apparent with the asynchronous method. In that case we only care if the operation is finished and successful.
    One can of course return dummy objects/values but providing Unit is more concise as it clearly marks a non-value.
    Instead of creating new instances it is recommended to use the singleton instance.
    Since:
    1.6
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static Unit Instance
      Static singleton representing the Unit.
    • Constructor Summary

      Constructors 
      Constructor Description
      Unit()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object obj)
      Simply compares the provided object to see if it is an instance of Unit.
      int hashCode()
      Always returns 69.
      java.lang.String toString()
      Always returns the string Unit
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • Instance

        public static final Unit Instance
        Static singleton representing the Unit.
        Since:
        1.7
    • Constructor Detail

      • Unit

        public Unit()
    • Method Detail

      • hashCode

        public int hashCode()
        Always returns 69.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        Always 69
        Since:
        1.7
      • equals

        public boolean equals​(java.lang.Object obj)
        Simply compares the provided object to see if it is an instance of Unit.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - The object to compare to
        Since:
        1.7
      • toString

        public java.lang.String toString()
        Always returns the string Unit
        Overrides:
        toString in class java.lang.Object
        Returns:
        The string Unit
        Since:
        1.7