Empty Java Generics

I understand that this problem is somewhat trivial, but I'm interested in knowing the "right" answer.

I am trying to expand , but my task does not require any parameters.android.os.AsyncTask< Params, Progress, Result >

Given that I have to overload protected Result doInBackground(Params... params),
what is the β€œbest” way to pass without parameters?

Currently, I use Objectas a type Paramsand run the task with: new MyAsyncTask().execute( (Object)null );
This is fully functional, but I'm new to Java and don't know if this is a good way to accomplish what I'm trying to do.

Obviously, I cannot put Paramssomething like voidor in the field null, but if I use a wildcard, I'm not sure what to do with the arguments doInBackground(Params... params).

Any suggestions?

+5
source share
4 answers

Use Void(pay attention to capital V) for any types of data that you do not need. Be sure to use annotation @Override, so the compiler will catch any problems. Here is an example application demonstrating this.

+9
source

Use a Voidclass.

android.os.AsyncTask<Void, Void, Void>
+5
source

Void. :

android.os.AsyncTask<Void, Void, Void>
+2

- , varargs, , :

new MyAsyncTask().execute();

Varargs "0 ".

+1

All Articles