Since I am relatively new to programming I don't now how to check if a method is not null. In the following code I need to check if the answers.get method is not null, how can I achieve this?
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);
}
}
Aucun commentaire:
Enregistrer un commentaire