RxJava 学习

RXJava 学习之路

1. 上链接 http://blog.danlew.net/2014/09/15/grokking-rxjava-part-1/

    Git Wiki https://github.com/ReactiveX/RxJava/wiki

Git上演示的都是以Groovy或者是JAVA8的lamada表达式来写的,对JAVA6程序员来说不是那易看,

(lamada表达式的确很强大)看来要紧跟步伐学习一下JAVA8的语法了。

本教程都是以JAVA6语法编写,out了一点点。。。

 

2. RXJava是个啥

你可以把它当成是一个响应式的框架,基于观察者模式实现。

RxJava tries to be very lightweight. It is implemented as a single JAR that is focused on just the Observable abstraction and related higher-order functions. You could implement a composable Future that is similarly unbiased, but Akka Futures for example come tied in with an Actor library and a lot of other stuff.)

 

3.RXJava 的主要组成

  • Observable  被观察对象,你要操作的对象
  • Subscribe     观察者,定义各个事件的操作方法

上个简单例子

public void print() {
		Observable<String> observable = Observable.create(new Observable.OnSubscribe<String>() {

			public void call(Subscriber<? super String> observer) {
				observer.onNext("123");
				observer.onCompleted();
			}

		});

		Subscriber<String> mySubscriber = new Subscriber<String>() {

			public void onCompleted() {
				System.out.println("complete");
			}

			public void onError(Throwable e) {
				System.out.println("onError");
			}

			public void onNext(String t) {
				System.out.println("onNext:" + t);
			}
		};

		observable.subscribe(mySubscriber);
	}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(java)