Tim Holloway wrote:If you define a variable as being of type Map, the only time that the insert method wouldn't be allowable would be if the value of the variable was null, since no methods can be executed when there's nothing to execute them on.
The mere fact that you declared it as type Map means that anything that gets assigned to that variable has promised (via the "implements" clause of the class definition) to honor each and every one of the methods declared in the Map interface as seen in the official JavaDocs.
Now a specific implementation of Map - say a read-only Map - might implement the "put" method as simply throwing an UnimplementedOperationException, but it's still a "put" method, regardless.
Paweł Baczyński wrote:
Does it even compile? You are using a variable that is not initialized.