有人可以告诉我dartlang实例如何抽象Map类吗?
问题描述:
为什么dart的哈希图不像Java的哈希图?
Why is dart's hashmap not like java's hashmap?
意思是Java的哈希图
Meaning that the hashmap of java is
public class HashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>, Cloneable, Serializable {}
但是dart是
abstract class HashMap<K, V> implements Map<K, V> {}
为什么抽象
?
!!!新问题!!!
!!!New Question!!!
- 我怎么知道哪个孩子类扩展抽象类HashMap?
- 我的另一个问题是,由于抽象类HashMap实现了Map接口,因此它没有实现
void clear()
函数。我想知道Map接口的void clear()
函数是在哪里实现的?我在抽象的HashMap类中找不到它。
- How would I know which child class extends "abstract class HashMap"?
- My other question is that since abstract class HashMap implements Map interface, it does not implement
void clear()
function. I wonder where thevoid clear()
function of the Map interface is implemented? I cannot find it in abstract HashMap class.
答
在Dart中,您可以拥有一个具体的工厂$
抽象
类上的c $ c>构造函数并转发到另一个类。尽管构造函数是针对抽象类调用的,但您获得的实例是具体的子类型。
In Dart you can have a concrete factory
constructor on an abstract
class and forward to another class. Although the constructor is called against the abstract class, the instance you get is of a concrete subtype.
abstract class Foo {
factory Foo() = Bar;
}
class Bar implements Foo {}
void main() {
print(Foo().runtimeType); // "Bar"
}