From 4f0cdca8ffe6c2700337a20c03e9c09bf5357a5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusuf=20K=2E=20=C3=96zcan?= Date: Sat, 29 Dec 2018 01:11:52 +0300 Subject: [PATCH] Update outdated java example in wiki #6331 (#6351) * Update outdated java example in wiki #6331 * update wiki page similar to README * keep the original example --- docs/How-To-Use-RxJava.md | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/docs/How-To-Use-RxJava.md b/docs/How-To-Use-RxJava.md index d10274d959..16d156caa9 100644 --- a/docs/How-To-Use-RxJava.md +++ b/docs/How-To-Use-RxJava.md @@ -11,15 +11,20 @@ You can find additional code examples in the `/src/examples` folders of each [la ### Java ```java -public static void hello(String... names) { - Observable.from(names).subscribe(new Action1() { - - @Override - public void call(String s) { - System.out.println("Hello " + s + "!"); - } +public static void hello(String... args) { + Flowable.fromArray(args).subscribe(s -> System.out.println("Hello " + s + "!")); +} +``` - }); +If your platform doesn't support Java 8 lambdas (yet), you have to create an inner class of ```Consumer``` manually: +```java +public static void hello(String... args) { + Flowable.fromArray(args).subscribe(new Consumer() { + @Override + public void accept(String s) { + System.out.println("Hello " + s + "!"); + } + }); } ``` @@ -397,4 +402,4 @@ myModifiedObservable = myObservable.onErrorResumeNext({ t -> Throwable myThrowable = myCustomizedThrowableCreator(t); return (Observable.error(myThrowable)); }); -``` \ No newline at end of file +```