Simple Option
Change this line in your class ChoicesQuestions
:
public Collection<Choice> setChoices() {
return choices;
}
I have initialized the collection in the constructor
public ChoicesQuestions () {
this.choices = new ArrayList < > ();
}
Rebooted Option
Just as you have it, you will create some confusion in the code, but it can be valid to shorten what you write a bit. (Personally I really like doing this in the set but I have found problems with debugging and reading)
I would change this line in your class ChoicesQuestions
:
public Collection<Choice> setChoices() {
return new ArrayList<>();
}
for this one:
public Collection<Choice> setChoices(Choice choice) {
choices.add(choice);
return this;
}
Not without first initializing the collection.
private Collection<Choice> choices = new ArrayList<>();
This can also be done in the constructor for added security.
Then I would call in this way to add continuously:
q.setChoices(new Choice("Verdadero", verdadero))
.setChoices(new Choice("Falso", false));