简体   繁体   English

Java:匿名 new View.OnClickListener() 可以替换为 lambda

[英]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匿名 new View.OnClickListener() 可以替换为 lambda

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

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).这是您的 IDE 提供的样式建议(我猜)。

You could ignore it, and there are probably IDE-specific settings to selectively turn off this kind of message.您可以忽略它,并且可能有特定于 IDE 的设置可以选择性地关闭此类消息。 But it is easy to just follow the IDE's suggestion and replace the anonymous class with a lambda;但是很容易按照 IDE 的建议将匿名类替换为 lambda; eg例如

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 匿名新 View.OnClickListener() 可以用 lambda 替换 - Anonymous new View.OnClickListener() can be replaced with lambda 新的OnClickListener()与新的View.OnClickListener() - new OnClickListener() vs new View.OnClickListener() setOnClickListener(new View.OnClickListener()创建java.lang.NullPointerException - setOnClickListener(new View.OnClickListener() creates java.lang.NullPointerException 类型View中的Java Android - setOnClickListener(View.OnClickListener)不适用于参数(new OnClickListener(){}) - Java Android - setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (new OnClickListener(){}) 未定义类型为new View.OnClickListener(){} - Undefined for the type new View.OnClickListener(){} 函数setOnClickListener(new View.OnClickListener() - Function setOnClickListener(new View.OnClickListener() 当 OnCLickListener 不是 static 时,我们如何直接使用新的 View.OnClickListener - How can we use new View.OnClickListener directly when OnCLickListener is not static View.OnClickListener,你能解释一下吗? - View.OnClickListener, can you explain? 如何抑制匿名 new runnable() 可以替换为 lambda - How can I suppress anonymous new runnable() can be replaced with lambda Android对于new View.OnClickListener(){}类型,未定义方法startActivity(Intent) - Android The method startActivity(Intent) is undefined for the type new View.OnClickListener(){}
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM