InvalidationTracker { @SuppressWarnings("unused") @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX) public void addWeakObserver(Observer observer) { addObserver(new WeakObserver(this, observer)); } @SuppressWarnings("WeakerAccess") @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX)  InvalidationTracker(RoomDatabase database, String... tableNames); @SuppressWarnings("WeakerAccess") @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX)  InvalidationTracker(RoomDatabase database, Map<String, String> shadowTablesMap,
            Map<String, Set<String>> viewTables, String... tableNames); @SuppressLint("RestrictedApi") @WorkerThread void addObserver(@NonNull Observer observer); @SuppressWarnings("unused") @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX) void addWeakObserver(Observer observer); @SuppressLint("RestrictedApi") @SuppressWarnings("WeakerAccess") @WorkerThread void removeObserver(@NonNull final Observer observer); @SuppressWarnings("WeakerAccess") void refreshVersionsAsync(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX) @WorkerThread void refreshVersionsSync(); @RestrictTo(RestrictTo.Scope.LIBRARY) @VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE) void notifyObserversByTableNames(String... tables); @Deprecated @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX) LiveData<T> createLiveData(String[] tableNames, Callable<T> computeFunction); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX) LiveData<T> createLiveData(String[] tableNames, boolean inTransaction,
            Callable<T> computeFunction);  }
@Test public void testWeak() throws InterruptedException { final AtomicInteger data = new AtomicInteger(0); InvalidationTracker.Observer observer = new InvalidationTracker.Observer("a") { @Override public void onInvalidated(@NonNull Set<String> tables) { data.incrementAndGet(); } }; mTracker.addWeakObserver(observer); setInvalidatedTables(0); refreshSync(); assertThat(data.get(), is(1)); observer = null; forceGc(); setInvalidatedTables(0); refreshSync(); assertThat(data.get(), is(1)); }