java - Java:解决未经检查的调用
问题描述
即使我已经在我的方法中引入了类型参数,我也遇到了未经检查的调用的问题。我不想压制警告,因为我很确定有办法以某种方式防止这种情况。
我的主要课程(这给了我警告)
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;
});
我的承诺课
// 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(...)
解决方案
没关系。我知道如何解决这个问题。
在.then(...)
我的Promise
课堂上我应该做
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);
}
}
警告就这样消失了
推荐阅读
- python-3.x - boto3 方法 generate_presigned_url() 中的行为不一致,有时 SignatureDoesNotMatch
- jquery - 每当触发 AJAX 请求时页面变为空白
- sql - 有没有办法将 SELECT、FROM、GROUPBY 语句的结果转换为新表?
- google-apps-script - 如何将匹配搜索条件的线程的内容提取到 Google 工作表中?
- python-3.x - 为什么只有一位整数输入有效,而不是两位整数?
- c++ - Arduino Uno 串行监视器不会打印整个输出;怎么修?
- python - Zarr 多线程读取组
- javascript - 如何在javascript中修复“TypeError:无法读取未定义的属性'长度'”
- makefile - 制作 args:是否有一个包含所有这些的变量?
- android - 在 Oculus Go 上侧加载应用时遇到问题