“在lambda表达式中使用的变量应为最终变量或有效地为最终变量”与“无法将值分配给最终变量”

时间:2019-07-15 09:34:02

标签: android

这是代码。

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

我该怎么办?

0 个答案:

没有答案
相关问题