Skip to content

Instantly share code, notes, and snippets.

@dlew
Created April 29, 2015 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dlew/e40ce3a003e7bc3900df to your computer and use it in GitHub Desktop.
Save dlew/e40ce3a003e7bc3900df to your computer and use it in GitHub Desktop.
import rx.Observable;
import rx.subjects.PublishSubject;
public class Property<T> {
private T value;
private PublishSubject<T> property;
public Property() {
property = PublishSubject.create();
}
public T getValue() {
return value;
}
public void setValue(T value) {
this.value = value;
property.onNext(value);
}
public Observable<T> observe() {
return property.asObservable();
}
}
import rx.Observable;
public class PropertySample {
public static void main(String[] args) {
Property<String> property = new Property<>();
property.observe().subscribe(System.out::println);
property.setValue("New Value from Setter");
Observable.just("New Value from Observable")
.subscribe(property::setValue);
System.out.println("Current val=" + property.getValue());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment