Can somebody answer me a Dartlang question about H

2019-08-29 17:29发布

问题:

The old question in Can somebody tell me HOW dartlang instances abstract Map class?

  1. How would I know which child class extends "abstract class Map"?
  2. My other question is that since abstract class HashMap implements Map interface, it does not implement void clear() function. I wonder where the void clear() function of the Map interface is implemented? I cannot find it in abstract HashMap class.

回答1:

You can start by reading the Map documentation:

  1. Built-in classes that implement Map are listed under:

    Implementers

    HashMap HttpSession LinkedHashMap MapMixin MapView

    If you mean how do you know which derived class is instantiated by Map's factory constructor, again, the documentation says so:

    Map<K, V> constructor

    Creates a Map instance with the default implementation, LinkedHashMap.

  2. If you look at the documentation for HashMap, it says:

    clear() → void

    Removes all pairs from the map. [...]

    inherited

    It explicitly tells you that the clear() implementation is inherited from a base class. If you click on it, it will take you to the class that it inherits it from.



标签: dart