DART:扩展类中抽象方法的实现
我在文件myclass.dart中有两个类:
abstract class A{
_myAbstractMethod();
}
class B extends A{
}
在这一点上,汇编说:缺少 One._method 的具体实现。 这是正确的行为!
当我将每个班级放在分离的文件上时,问题出现了。当我将B类声明移至另一个文件时,该汇编不再告诉丢失的实现。
请注意A类中的方法是私有的,并且仅在分离文件中的每个类都发生“问题”。
I have two class in file myclass.dart:
abstract class A{
_myAbstractMethod();
}
class B extends A{
}
At this point the compilation says: MISSING CONCRETE IMPLEMENTATION OF One._Method.
This is the correct behavior!
The problem came when I put each class on separated files. When I move class B declaration to another file, the compilation do not tell anymore the missing implementation.
Pay attention that the method on class A is private, and the "problem" only occurs with each class in separated files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是预期的行为,因为类
a
上的方法是库私有的。这意味着,当放入第二个库时,类
b
不知道a
具有一种名为_MyAbStractMethod的方法,如果这样做,它甚至无法编写名称(在
b
的库中编写_MyAbstractMethod
代表第二个库的私人名称)。因此,从
b
的角度来看,它正确实现了a
's(空)接口。一切都很好。
a
类不同意,但无能为力。要使
b
类完整,编译器添加了合成_MyAbstractMethod
(使用a
的名称)实现,该实现在调用时会投掷。这是预期的行为。
This is expected behavior because the method on the class
A
is library private.That means that when put in a second library, the class
B
doesn't know thatA
has a method named_myAbstractMethod
, and if it did, it couldn't even write the name (writing_myAbstractMethod
in the library ofB
represents a different name, private to the second library).So, from
B
's perspective it correctly implementsA
's (empty) interface.All is well.
The
A
class disagrees, but there is nothing it can do.To make the
B
class complete, the compiler adds a synthetic_myAbstractMethod
(usingA
's name) implementation which throws when called.This is expected behavior.