ResultCompat
- Kotlin
- Java
ResultCompat is a class defined for Java compatibility and provides functionality similar to kotlin Result<T>.
Summary
| Public constructors | |
|---|---|
java-static ResultCompat<Boolean> | Stores the given data as success data and returns a ResultCompat object. |
java-static ResultCompat<Boolean> | Stores the given Throwable as a failure error and returns a ResultCompat object. |
| Public functions | |
|---|---|
| T? | Returns T if success data exists; otherwise, returns null. |
| T | Returns T if success data exists; otherwise, throws an exception. |
If a failure error exists, returns Throwable; otherwise, returns null. | |
ResultCompat<Boolean> | Registers functions to handle success and failure. |
ResultCompat<Boolean> | Registers a function to handle success. |
ResultCompat<Boolean> | Registers a function to handle failure. |
| Public properties | |
|---|---|
| Boolean | Returns |
| Boolean | Returns |
Public methods
getOrNull()
fun <T> getOrNull(): T?
If a success data exists, returns T; otherwise, returns null.
| Returns | |
|---|---|
T? | Success data |
getOrThrow()
fun <T> getOrThrow(): T
If a success data exists, returns T; otherwise, returns null.
| Returns | |
|---|---|
T | Success data |
exceptionOrNull()
fun <T> exceptionOrNull(): Throwable?
If a failure error exists, returns Throwable; otherwise, returns null.
| Returns | |
|---|---|
| Failure error |
fold()
fun <T> fold(onSuccess: (T) -> Unit, onFailure: (Throwable) -> Unit): ResultCompat<T>
Registers functions to handle success and failure.
| Parameters | |
|---|---|
(T) -> Unit | Lambda to handle success |
(Throwable) -> Unit | Lambda to handle failure |
| Returns | |
|---|---|
ResultCompat<Boolean> | ResultCompat |
onSuccess()
fun <T> onSuccess(action: (T) -> Unit): ResultCompat<T>
Registers a function to handle success.
| Parameters | |
|---|---|
(T) -> Unit | Lambda to handle success |
| Returns | |
|---|---|
ResultCompat<Boolean> | ResultCompat |
onFailure()
fun <T> onFailure(action: (Throwable) -> Unit): ResultCompat<T>
Registers a function to handle failure.
| Parameters | |
|---|---|
(Throwable) -> Unit | Lambda to handle failure |
| Returns | |
|---|---|
ResultCompat<Boolean> | ResultCompat |
ResultCompat is a class defined for Java compatibility and provides functionality similar to kotlin Result<T>.
Summary
| Public constructors | |
|---|---|
static ResultCompat&lt;Boolean&gt; | Stores the given data as success data and returns a ResultCompat object. |
static ResultCompat<Boolean> | Stores the given Throwable as a failure error and returns a ResultCompat object. |
| Public methods | |
|---|---|
| @Nullable T | Returns T if success data exists, otherwise returns null. |
| @NonNull T | If a success data exists, returns T; otherwise, returns null. |
Returns Throwable if a failure error exists, otherwise returns null. | |
@NonNull ResultCompat<Boolean> | Registers functions to handle success and failure. |
@NonNull ResultCompat<Boolean> | Registers a function to handle success. |
@NonNull ResultCompat<Boolean> | Registers a function to handle failure. |
| boolean | Returns |
| boolean | Returns |