@Test public void testOwnedBy() { final ViewModelStore store = new ViewModelStore(); ViewModelStoreOwner owner = new ViewModelStoreOwner() { @NonNull @Override public ViewModelStore getViewModelStore() { return store; } }; ViewModelProvider provider = new ViewModelProvider(owner, new NewInstanceFactory()); ViewModel1 viewModel = provider.get(ViewModel1.class); assertThat(viewModel, is(provider.get(ViewModel1.class))); }
@NonNull @MainThread public <T extends ViewModel> T get(@NonNull Class<T> modelClass) { String canonicalName = modelClass.getCanonicalName(); if (canonicalName == null) { throw new IllegalArgumentException("Local and anonymous classes can not be ViewModels"); } return get(DEFAULT_KEY + ":" + canonicalName, modelClass); }
ViewModelProvider { @NonNull @MainThread public <T extends ViewModel> T get(@NonNull Class<T> modelClass) { String canonicalName = modelClass.getCanonicalName(); if (canonicalName == null) { throw new IllegalArgumentException("Local and anonymous classes can not be ViewModels"); } return get(DEFAULT_KEY + ":" + canonicalName, modelClass); } }
ViewModelProvider { @NonNull @MainThread public <T extends ViewModel> T get(@NonNull Class<T> modelClass) { String canonicalName = modelClass.getCanonicalName(); if (canonicalName == null) { throw new IllegalArgumentException("Local and anonymous classes can not be ViewModels"); } return get(DEFAULT_KEY + ":" + canonicalName, modelClass); } ViewModelProvider(@NonNull ViewModelStoreOwner owner, @NonNull Factory factory);  ViewModelProvider(@NonNull ViewModelStore store, @NonNull Factory factory); }
ViewModelProvider { @NonNull @MainThread public <T extends ViewModel> T get(@NonNull Class<T> modelClass) { String canonicalName = modelClass.getCanonicalName(); if (canonicalName == null) { throw new IllegalArgumentException("Local and anonymous classes can not be ViewModels"); } return get(DEFAULT_KEY + ":" + canonicalName, modelClass); } ViewModelProvider(@NonNull ViewModelStoreOwner owner, @NonNull Factory factory);  ViewModelProvider(@NonNull ViewModelStore store, @NonNull Factory factory); @NonNull @MainThread T get(@NonNull Class<T> modelClass); @NonNull @MainThread T get(@NonNull String key, @NonNull Class<T> modelClass); }
ViewModelProvider { @NonNull @MainThread public <T extends ViewModel> T get(@NonNull Class<T> modelClass) { String canonicalName = modelClass.getCanonicalName(); if (canonicalName == null) { throw new IllegalArgumentException("Local and anonymous classes can not be ViewModels"); } return get(DEFAULT_KEY + ":" + canonicalName, modelClass); } ViewModelProvider(@NonNull ViewModelStoreOwner owner, @NonNull Factory factory);  ViewModelProvider(@NonNull ViewModelStore store, @NonNull Factory factory); @NonNull @MainThread T get(@NonNull Class<T> modelClass); @NonNull @MainThread T get(@NonNull String key, @NonNull Class<T> modelClass);  }