N
N
Neonoviiwolf2019-03-13 17:49:47
Android
Neonoviiwolf, 2019-03-13 17:49:47

How to understand such Java code with lambda?

Kind
There is a fragment, in it it is a lot of CheckedTextView. In fragment

implements View.OnClickListener

to make on all CheckedTextView listener
So here is
checked.setOnClickListener(this::onClick);
or
checked.setOnClickListener(this);

It looks like the output is the same, but what's the difference?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Vodakov, 2019-03-13
@WaterSmith

The difference is that when used, the fragment may not implement View.OnClickListener, because the listener is not it, but an anonymous class generated by the lambda. If your fragment still implements View.OnClickListener, then the lambda is completely out of place and redundant.

D
Denis Zagaevsky, 2019-03-13
@zagayevskiy

The difference is that in the first case, an additional anonymous class is created.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question