【问题标题】:How do I create a class with the same name as another class/interface?如何创建与另一个类/接口同名的类?
【发布时间】:2012-06-29 03:07:11
【问题描述】:

我想创建自己的名为 Point 的类,但在 html 库中遇到了同名接口的问题。我错过了什么可以让我摆脱“已经定义为接口”的泡菜?

class Point
{
//r is x
// g is the difference between x+y and 0
// b is y
  num r,g,b;
  Point(this.r, this.g, this.b);
...
}

内部错误: 'http://127.0.0.1:3030/C:/Users/.../Desktop/dart/workspace/projects/.../Point.dart':错误:第 1 行 pos 7:'Point' 已定义作为接口类 点

【问题讨论】:

标签: dart


【解决方案1】:

在导入具有要重用的类/接口的库时,使用前缀对其进行限定,这将强制您显式使用原始类,并隐式使用新类。

#import('dart:html', prefix:'html');

html.Point 将使用 html 中的点接口。
Point 将使用您项目/库中的类。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2020-11-21
  • 2014-12-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-07
  • 1970-01-01
相关资源
最近更新 更多