And*_*dro 0 java lambda functional-programming java-8 java-stream
如何使用Java 8 lambda/stream()以更直观的方式在函数式编程中编写此方法?
int animation = R.style.DialogAnimationSlideHorizontal;
String body;
String subject = mSubjectView.getText().toString();
BaseDialog dialog = dialogFactory.getType(DialogTypes.DIALOG_FULL);
if (!checkFields()) {
// one of the recipients is invalid.
body = getString(R.string.bad_address);
dialog.showDialog(body, animation, new DialogBuilder.Positive() {
@Override
public void handleClick(DialogInterface dialogInterface, View view) {
// do nothing
}
});
} else if (Helpers.isEmpty(subject)) {
// Yup, empty... send the message without a subject?
body = getString(R.string.empty_subject_compose);
dialog.showDialog(body, animation, new DialogBuilder.Positive() {
@Override
public void handleClick(DialogInterface dialogInterface, View view) {
// user accepted to send anyway.
mWebView.getComposeContent();
}
});
} else {
// everything is correct! send the message.
mWebView.getComposeContent();
}
Run Code Online (Sandbox Code Playgroud)
用lambdas替换所有匿名类
new DialogBuilder.Positive() {
@Override
public void handleClick(DialogInterface dialogInterface, View view) {
...
}
}
|
V
(dialogInterface, view) -> { /*do nothing*/ }
(dialogInterface, view) -> { mWebView.getComposeContent(); }
Run Code Online (Sandbox Code Playgroud)
我不知道如何在这里应用Stream API.
| 归档时间: |
|
| 查看次数: |
1006 次 |
| 最近记录: |