如何避免编译器警告从未使用参数“ x” [英] How to avoid complier warning Parameter 'x' is never used
问题描述
建议在Android Studio 3.3中解决此类编译器警告的最佳方法
Suggest the best way to solve this type of compiler warning in Android Studio 3.3
注意:我找到了许多避免警告的解决方案,并取消了Studio检查。
Note: I found many solutions to avoid the warnings and uncheck the Studio inspection. But I am expecting something different.
示例:
如果警告从未使用过参数'view1',则该按钮位于onClick方法中。
Example: If warning Parameter 'view1' is never used is in the button onClick method.
方法
fun buttonClicked(view1: View) {
// Call Intent to new Activity .
// Parameter **view1** is not used }
调用方法从XML
<Button
android:id="@+id/button_id"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:onClick="@{viewModel::buttonClicked}"
android:text="@string/example" />.
所以我们需要(view1:View)参数作为onClick方法。但是没有使用。如何解决此警告? (仅举一个例子)。
So we need (view1: View) parameter for the method for onClick. But it is not used. How can I solve this warning?. (Just one example).
推荐答案
我只是确保以便宜的方式使用view变量,这样错误就会消失:
I just make sure to use the view variable in a cheap way so the error goes away:
Log.d("IGNORE", "Logging view to curb warnings: $view1")
这不是一个很好的答案,但是一个Log不会降低应用程序的速度,并且可以解决问题
Not an elegant answer, but one Log isn't gonna slow down the app and it does the trick
这篇关于如何避免编译器警告从未使用参数“ x”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!