安卓 Lint 警告 : "Redundant array creation for calling varargs method"

标签 android android-lint

我在我的 Android 项目中针对以下代码的 new Void[] {} 部分收到上述 Lint 警告:

new AsyncTask<Void, Void, Exception>() {

    @Override
    protected void onPreExecute() {
        showToast("Restarting NFC...");
    }

    @Override
    protected Exception doInBackground(Void... params) {
        try {
            disableNfcForegroundDispatch();
            Thread.sleep(1000L);
            enableNfcForegroundDispatch();
            return null;
        }
        catch (Exception e) {
            return e;
        }
    }

    @Override
    protected void onPostExecute(Exception e) {
        if (e == null) {
            showToast("...NFC restarted.");
        }
        else {
            Log.e(LOG_TAG, "Could not restart NFC!", e);
            showToast("Could not restart NFC: " + e);
        }
    }

}.execute(new Void[] {});

我无法用 null 替换有问题的 new Void[] {},那么正确的解决方案是什么?

最佳答案

将参数列表留空:

.execute();

关于安卓 Lint 警告 : "Redundant array creation for calling varargs method",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39142878/

相关文章:

java - 如何使用 RecyclerView 的 SelectionTracker 无需长按即可选择第一项

java - 创建自定义 Lint Java 检测器

android - 奇怪的 Lint 警告 - 在布局文件 : "" 中发现意外文本

android - Android 中的其他 lint 规则

android - 在 libgdx 中,如何从后退按钮获取输入?

java - 奇怪的 android.content.res.Resources$NotFoundException : Unable to find resource ID #0x7f06008d

android - 从 Pipeline 项目发布 Android Lint 结果

Android Studio 3.0 lint 找不到缺少的权限

android - 在 android 2.2 中使用 Cursor Adapters 和 Content Provider 的正确方法是什么

android - OpenGL ES Android 矩阵转换