Skip to content

Instantly share code, notes, and snippets.

@user-mw
Last active December 7, 2019 13:31
Show Gist options
  • Save user-mw/bb821bc16e69fe73300cbe8ff3ce0939 to your computer and use it in GitHub Desktop.
Save user-mw/bb821bc16e69fe73300cbe8ff3ce0939 to your computer and use it in GitHub Desktop.
ViewModelProvider get(@nonnull String key, @nonnull Class<T> modelClass)
public <T extends ViewModel> T get(@NonNull String key, @NonNull Class<T> modelClass) {
ViewModel viewModel = mViewModelStore.get(key);
if (modelClass.isInstance(viewModel)) {
return (T) viewModel;
} else {
// Сode
}
viewModel = mFactory.create(modelClass);
mViewModelStore.put(key, viewModel);
return (T) viewModel;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment