我对 lambda 表达式有疑问;我在返回类型方法中使用了 lambda 表达式,但return isDownloaded.get()在 lambda 表达式之前执行。我如何等待 lambda 完成?
public boolean isDowloaded(int id) {
AtomicReference<Boolean> isdownload = new AtomicReference<>(false);
AtomicReference<List<Download>> downloadList = new AtomicReference<>();
MyApplication.getInstance().getFetch().getDownloads(downloads -> {
downloadList.set(downloads);
for (int i = 0; i < downloadList.get().size(); i++) {
if (downloadList.get().get(i).getExtras().getString("id","").equals(String.valueOf(id)) ) {
PlayerConstants.SONG_NUM = i;
isdownload.set(true);
}
}
});
// always return false in this case
return isdownload.get();
}
幕布斯6054654
相关分类