Skip to content

Instantly share code, notes, and snippets.

@just-4-fun
just-4-fun / gist:449c032df66a978e8c308258d8429888
Created May 9, 2018 09:24
Result<T> class implementation
/**
* The result of some method call provides the caller with a requested [value] if the call is successful or an [exception] if failed.
* Replaces the usual approach to throw an exception or return the null in case of an execution failure.
* Note: [Result.exception] of the successful [Result] is always `null`.
*/
@Suppress("UNCHECKED_CAST")
class Result<T> {
private var result: Any? = null
private var success = true