RxJava is a Java VM implementation of Reactive Extensions[1]使用可观察的序列来组成异步和基于事件的程序的库。
<!-- https://mvnrepository.com/artifact/io.reactivex.rxjava3/rxjava -->
<dependency>
<groupId>io.reactivex.rxjava3</groupId>
<artifactId>rxjava</artifactId>
<version>3.1.5</version>
</dependency>
package rxjava.examples;
import io.reactivex.rxjava3.core.*;
public class HelloWorld {
public static void main(String[] args) {
Flowable.just("Hello world").subscribe(System.out::println);
}
}
Observable.create(new Observable.OnSubscribe<String>() {
@Override
public void call(Subscriber<? super String> subscriber) {
Log.e(TAG, "call");
subscriber.onNext("hello");
subscriber.onNext("beauty");
subscriber.onCompleted();
}
})
.subscribe(new Subscriber<String>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(String s) {
Log.e(TAG, "onNext s: " + s);
}
});
05-31 14:36:06.469 29241-29241/? E/rx2: call
05-31 14:36:06.470 29241-29241/? E/rx2: onNext s: hello
05-31 14:36:06.470 29241-29241/? E/rx2: onNext s: beauty
05-31 14:36:06.470 29241-29241/? E/rx2: onCompleted
https://blog.csdn.net/afdafvdaa/article/details/124437536
rx.functions.Func1 -> io.reactivex.rxjava3.functions.Function
Func1.call -> Function.apply
rx.functions.Action1 -> io.reactivex.rxjava3.functions.Consumer
Action1.call -> Consumer.accept
Observable.OnSubscribe -> ObservableOnSubscribe