这是代码。
public static void updateTips(String UserID, long tips, boolean add) {
FirebaseFirestore db = FirebaseFirestore.getInstance();
db.collection("Users").document(UserID).get()
.addOnSuccessListener(documentSnapshot -> {
if (add) {
tips += documentSnapshot.getLong("balance"); // ERROR HERE
}
db.collection("Users").document(UserID).update("tips", tips)
.addOnSuccessListener(aVoid -> Log.d("USERS", "Tips correctly updated"))
.addOnFailureListener(e -> Log.d("USERS", "Tips NOT updated. ERROR" + e.toString()));
})
.addOnFailureListener(e -> Log.d("USERS", "Tips NOT updated. ERROR" + e.toString()));
}
编辑tips
值(long
类型)时出现错误。
系统显示Variable used in lambda expression should be final or effectively final
。
然后,我将tips
更改为final long
类型。但系统显示Cannot assign value to final variable
!
我该怎么办?