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



我在Android项目中获得上述Lint警告,用于以下代码的new Void[] {}部分:

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();

最新更新