void () { List<Disposable> run = new ArrayList<>(); //noinspection EqualsWhichDoesntCheckParameterClass Disposable disposable0 = new Disposable() { @Override public void dispose() { run.add(this); } @Override public int hashCode() { return 0; } @Override public boolean equals(Object obj) { return true; } }; //noinspection EqualsWhichDoesntCheckParameterClass Disposable disposable1 = new Disposable() { @Override public void dispose() { run.add(this); } @Override public int hashCode() { return 0; } @Override public boolean equals(Object obj) { return true; } }; assertEquals(disposable0, disposable1); // for children Disposable parent = Disposer.newDisposable(); Disposer.register(parent, disposable0); Disposer.register(parent, disposable1); Disposer.dispose(parent); assertEquals(2, run.size()); assertSame(disposable1, run.get(0)); assertSame(disposable0, run.get(1)); }