Dynamic method selection is so confusing!

Here is Crystal’s DMS Flow chart from a few semesters ago. You can follow steps methodically.

Note that DMS is optional and out of scope for Summer 2025. The first slide of Crystal’s flowchart is in scope, as there is no method selection involved.

ListSet

Why does ListSet::remove have that given line?

As mentioned in the comment, the reason that we need the line is out of scope. Specifically, the List interface has two remove methods:

  • remove(int index), that removes an element at a specific index
  • remove(Object elem), that removes a specific thing from the list

We would like to use the latter, so we must “autobox” the given int to Integer with the given assignment statement.