Created
March 2, 2017 15:18
-
-
Save fkmhrk/e8d4977fc1d6c22bc5a717b339074678 to your computer and use it in GitHub Desktop.
Method chain vs sequential statements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// We often see sequential method call. | |
AlertDialog.Builder builer = new AlertDialog.Builder(this); | |
builer.setTitle("タイトル"); | |
builer.setMessage("メッセージ"); | |
builer.setPositiveButton(android.R.string.ok, this.listener); | |
// We can use method chain. | |
AlertDialog.Builder builer = new AlertDialog.Builder(this); | |
.setTitle("タイトル") | |
.setMessage("メッセージ") | |
.setPositiveButton(android.R.string.ok, this.listener); | |
// We often use method chain in RxJava/Promise | |
Observable<Moke> o = this.sendRequest(...) | |
.map(new Function<>{...}) | |
.map(new Function<>{...}); | |
// In this case, if we use sequential method call... | |
Observable<Moke> o = this.sendRequest(...); | |
o = o.map(new Function<>{...}); // o becomes another object | |
o = o.map(new Function<>{...}); // o becomes another object | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment