Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Java: Anonymous new View.OnClickListener() can be replaced with lambda

Can anyone help me with this error

Anonymous new View.OnClickListener() can be replaced with lambda

button_copy.setOnClickListener(new View.OnClickListener() {
    
      @Override
      public void onClick(View v) {
            String scanned_text = textview_data.getText().toString();
            copyToClipBoard(scanned_text);
      }
});

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Can anyone help me with this error

As noted in the comments it is NOT an error. It is style advice provided by your IDE (I guess).

You could ignore it, and there are probably IDE-specific settings to selectively turn off this kind of message. But it is easy to just follow the IDE’s suggestion and replace the anonymous class with a lambda; e.g.

button_copy.setOnClickListener(
        v -> copyToClipBoard(textview_data.getText().toString());
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading