3 ms·
Actually, this is similar to what you can do in Java by using lambdas (Retrolambda for pre-Java 8, e.g. Android pre-SDK 24). Excerpt from a blog post [1] about
by htgb 9y ago
Actually, this is similar to what you can do in Java by using lambdas (Retrolambda for pre-Java 8, e.g. Android pre-SDK 24). Excerpt from a blog post [1] about it:
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// do something here
}
});
can be replaced with
mButton.setOnClickListener((View v) -> {
// do something here
});
which is nice for all callbacks, but especially together with ReactiveX where they are abundant.
[1] http://zserge.com/blog/android-lambda.html http://zserge.com/blog/android-lambda.html
- tjohns 9y agoWorth noting for completeness... In Kotlin you can take that a step further: mButton.setOnClickListener { /* do something here */ } (In addition to SAM conversions, both the parenthesis and input variable are optional.)