安卓 Lint 警告: "为调用可变参数方法创建了冗余的数组"

3

在我的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[] {},那么正确的解决方案是什么?


1
你试过不带参数吗? - Mike M.
1
是的,这个已经起作用了。谢谢! - ban-geoengineering
1个回答

4

不传入任何参数:

.execute();

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接