Skip to content

Instantly share code, notes, and snippets.

@kakai248
Created October 2, 2017 09:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kakai248/f3aa28187affd8b7f941cfafe26a445f to your computer and use it in GitHub Desktop.
Save kakai248/f3aa28187affd8b7f941cfafe26a445f to your computer and use it in GitHub Desktop.
public class ViewModelInjectionFactory<VM extends ViewModel> implements ViewModelProvider.Factory {
private Lazy<VM> viewModel;
@Inject
public ViewModelInjectionFactory(Lazy<VM> viewModel) {
this.viewModel = viewModel;
}
@Override
@SuppressWarnings("unchecked cast")
public <T extends ViewModel> T create(Class<T> modelClass) {
return (T) viewModel.get();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment