本文介绍了Java Lambda表达式错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的Java 8代码中,
In my Java 8 code,
public ChangePersonsName(String email, final String password, final String wantedUsername, final String uuid, final long time, int latency, int[] requests, int[] proxyRequests) throws IOException {
final AtomicReference<Object> token = new AtomicReference<Object>();
final AtomicReference<ArrayList<?>> newHeaders = new AtomicReference<ArrayList<?>>();
new Thread(() -> {
boolean lock = true;
while (lock) {
if (time - System.currentTimeMillis() > 60000) continue;
Map<Header[], String> loginResults = null;
try {
loginResults = this.login(email, password, uuid);
}
catch (IOException e) {
e.printStackTrace();
}
String token = loginResults.entrySet().iterator().next().getValue();
Header[] headers = loginResults.entrySet().iterator().next().getKey();
newHeaders.set(new ArrayList<Object>());
for (Header header : headers) {
if (!header.toString().startsWith("Set-Cookie:")) continue;
((List<BasicHeader>)newHeaders.get()).add(new BasicHeader("Cookie", header.toString().split("Set-Cookie: ")[1]));
}
lock = false;
}
}
).start();
new Timer().schedule(new TimerTask(){
您会注意到
String token = loginResults.entrySet().iterator().next().getValue();
引发编译错误,
我的问题是,如何解决这个问题?我对Java很陌生,我可能应该知道如何解决这个问题,但是我不知道.
My question is, How would one go about fixing this? I'm pretty new to Java, I should probably know how to fix this, but i don't.
推荐答案
在此范围内,您已经具有名称为token
的变量.您已经在第二行中声明了它.要修复,只需重命名第二个变量:
You already have variable with name token
in this scope. You've declared it in 2nd row. To fix just rename 2nd variable:
String newToken = loginResults.entrySet().iterator().next().getValue();
这篇关于Java Lambda表达式错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!