由于我对编程比较陌生,所以我现在不知道如何检查方法是否不为空。在下面的代码中,我需要检查answers.get方法是否不为空,我该如何实现这一点?
public class SharedViewModel extends ViewModel {
private HashMap<Integer, MutableLiveData<String>> answers = new HashMap<>();
public MutableLiveData<String> getAnswer(int questionId) {
return answers.get(questionId);
}
public void setAnswer(int questionId, String answer) {
// TODO make sure that answers.get is not null
answers.get(questionId).setValue(answer);
}
}
慕虎7371278
牧羊人nacy
蓝山帝景
相关分类