Skip to content

Instantly share code, notes, and snippets.

@lewisevans
Last active November 7, 2018 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lewisevans/76062114af186777f8fca5120d5eb086 to your computer and use it in GitHub Desktop.
Save lewisevans/76062114af186777f8fca5120d5eb086 to your computer and use it in GitHub Desktop.
class ViewModelFactory <T : ViewModel> @Inject constructor(private val viewModel: Lazy<T>) : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel?> create(modelClass: Class<T>): T = viewModel.get() as T
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment