Question

While reading Google's tutorial on Cloud Endpoints for Android, I came across this code where they have passed a variable of type Void to a function. Is this correct? If yes, how does that work? Also, what is the point of passing variables named "unused" to functions if they are not going to be used by those functions?

public void onClickListGreetings(View unused) {

AsyncTask<Void, Void, HelloGreetingCollection> getAndDisplayGreeting =
        new AsyncTask<Void, Void, HelloGreetingCollection> () {
            @Override
            protected HelloGreetingCollection doInBackground(Void... unused) {

                // more code

As always, thanks so much for helping out!! :)

Was it helpful?

Solution

That isn't a variable. It's a generic argument of the Void class.

Edit- As for the varargs, they're unused, so it doesn't really matter that you can't instantiate a Void.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top