有人可以告诉我dartlang实例如何抽象Map类吗? [英] Can somebody tell me HOW dartlang instances abstract Map class?

查看:62
本文介绍了有人可以告诉我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!!!


  1. 我怎么知道哪个孩子类扩展抽象类HashMap?

  2. 我的另一个问题是,由于抽象类HashMap实现了Map接口,因此它没有实现
    void clear()
    函数。我想知道Map接口的 void clear()函数是在哪里实现的?我在抽象的HashMap类中找不到它。

  1. How would I know which child class extends "abstract class HashMap"?
  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.


推荐答案

在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"
}

这篇关于有人可以告诉我dartlang实例如何抽象Map类吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆