kennyyi
06/04/2017, 11:28 AMopen class PostTask() : AsyncTask<String, Void, Void>() {
override fun doInBackground(vararg params: String?): Void {
NetworkModule().getRetrofitClient(URL_TEST).create(PostService::class.java)
.postData(params[0])
}
}
Android studio shows [TYPE_MISMATCH] error for params[0]
, and if I change String?
to String
, the parameter’s type of doInBackground, [NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY] error is happened.
1. How to compare type Type?
and Type
?
2. How to write return statement, if return type was Void
?vyacheslav.gerasimov
06/04/2017, 12:53 PMUnit
type in Koltin corresponds to void
type in Java, try this:
open class PostTask() : AsyncTask<String, Unit, Unit>() {
override fun doInBackground(vararg params: String) {
NetworkModule().getRetrofitClient(URL_TEST).create(PostService::class.java)
.postData(params[0])
}
}
kennyyi
06/05/2017, 1:37 AM