I'm having an issue with unchecked calls even though I already introduced the type parameter to my method. I don't want to suppress the warnings because I'm pretty sure there's a way to prevent that somehow.
My main class (which is giving me the warning)
HttpUtil.fetch(
url,
headers,
HttpRequest.Method.POST,
new HttpRequest.Form.Builder(HttpRequest.Form.Encoding.URL_ENCODED)
.set("password", iLoginPass.getText().toString())
.set("login", iLoginUser.getText().toString())
.build()
)
.then(HttpResponse::getBody)
.then((Promise.Resolver<Void, Document>) value -> {
final Elements elems = value.body().getElementsByTag("table");
Toast.makeText(MainActivity.this, elems.text(), Toast.LENGTH_LONG).show();
return null;
});
My Promise class
// T: input, U: progress (unused but just in case), V: output (resolved value)
public class Promise<T, U, V> {
// RV: new return value (aka. resolved value)
public <RV> Promise then(final Resolver<RV, V> nextResolver){
return new Promise<V, U, RV>(nextResolver, this.rejector, resolvedValue);
}
}
Also ignore the HttpUtil.fetch
function because it returns a Promise object with parameter types <String, Void, HttpResponse>
. The body should return another object from Document class which shouldn't be a problem because if I did .<Document>then(...)
it tells me 'the parameterized type is redundant' and wanted me to infer the type. Also, the important thing to note here is the warning pop out only if I did with two or more .then(...)
Never mind. I know how to fix this.
In .then(...)
function in my Promise
class I should do
public class Promise<T, U, V> {
public <RV> Promise<V, U, RV> then(final Resolver<RV, V> nextResolver){
return new Promise<V, U, RV>(nextResolver, this.rejector, resolvedValue);
}
}
With that the warning went away