Package javascalautils
Class Unit
- java.lang.Object
-
- javascalautils.Unit
-
- All Implemented Interfaces:
java.io.Serializable
public final class Unit extends java.lang.Object implements java.io.SerializableRepresents the type scala.Unit.
The usage of Unit is for situations where one returns types such asTryorFuturethat are not meant to hold a value.
E.g.
The example illustrates deleting something but the only thing we care of is if the operation was successful.Try<Unit> deleteSynchronous(String id) Future<Unit> deleteAsynchronous(String id)
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 thesingletoninstance.- Since:
- 1.6
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Unit()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object obj)Simply compares the provided object to see if it is an instance ofUnit.inthashCode()Always returns69.java.lang.StringtoString()Always returns the stringUnit
-
-
-
Field Detail
-
Instance
public static final Unit Instance
Static singleton representing the Unit.- Since:
- 1.7
-
-
Method Detail
-
hashCode
public int hashCode()
Always returns69.- Overrides:
hashCodein classjava.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 ofUnit.- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- The object to compare to- Since:
- 1.7
-
toString
public java.lang.String toString()
Always returns the stringUnit- Overrides:
toStringin classjava.lang.Object- Returns:
- The string
Unit - Since:
- 1.7
-
-