I don't understand how a set determines when two objects are equal. More specific, when does the add
method of a set, really adds a new object, and when doesn't it act a new object, because the object is already in the set ?
For example, I have objects from the following class:
class Action {
final Function function;
final String description;
Action(this.function, this.description);
call() => function();
toString() => description;
}
Now I would think that the following set would contain 2 elements, as 2 of them are equal:
void main() {
Set<Action> actions = new Set()
..add(new Action(() => print("a"), "print a"))
..add(new Action(() => print("a"), "print a"))
..add(new Action(() => print("b"), "print b"));
}
But instead, this set contains 3 Action
objects. See the demo. How can I make sure that equal objects are seen as equal in the set ?