Skip to content

Instantly share code, notes, and snippets.

@akshaybhange
Last active February 11, 2020 16:00
Show Gist options
  • Save akshaybhange/8688dba1c2b90a907d6a3c05dbddca0f to your computer and use it in GitHub Desktop.
Save akshaybhange/8688dba1c2b90a907d6a3c05dbddca0f to your computer and use it in GitHub Desktop.
A generic class that contains data and status about loading this data.
sealed class Resource<T>(
val data: T? = null,
val message: String? = null
) {
class Success<T>(data: T) : Resource<T>(data)
class Loading<T>(data: T? = null) : Resource<T>(data)
class Error<T>(message: String, data: T? = null) : Resource<T>(data, message)
}
enum class Status {
SUCCESS,
ERROR,
LOADING
}
@rat
Copy link

rat commented Feb 11, 2020

omg, examples in java is better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment