androidlambdaretrolambda

Why this method call can not be converted into lambda?


Consider the following code:

recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                //some code here
            }
        });

Why can it not be translated into this:

recyclerView.addOnScrollListener((recyclerView, dx, dy) -> {
    // some code here
});

I'm using retrolambda in AndroidStudio.


Solution

  • Because RecyclerView.OnScrollListener is an abstract class and actually has more methods than just onScrolled.