Skip to content

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

Closed
@nsk-mironov

Description

@nsk-mironov
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions