Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.0.0-RC5] distinctUntilChanged doesn't work nicely with mutable objects #4743

Closed
nsk-mironov opened this issue Oct 21, 2016 · 1 comment
Closed
Labels

Comments

@nsk-mironov
Copy link
Contributor

public class Main {
  static class Header {
    String name = "key";
    String value = "one";
  }

  public static void main(String[] args) {
    final Header header = new Header();
    final BehaviorSubject<Header> subject = BehaviorSubject.createDefault(header);

    subject.distinctUntilChanged(new Function<Header, Object>() {
      @Override
      public Object apply(final Header header) throws Exception {
        return header.value;
      }
    }).subscribe(new Consumer<Header>() {
      @Override
      public void accept(final Header header) throws Exception {
        System.out.println("Name = " + header.name + ", Value = " + header.value);
      }
    });

    header.value = "two";
    subject.onNext(header);
  }
}

Output:

Name = key, Value = one

Expected output:

Name = key, Value = one
Name = key, Value = two

The same code used to work as expected with 2.0.0-RC4 and all previous RxJava versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants