@protected是否有@friend功能?
我正在使用DART注释@protected
,因为我想将成员限制为仅从单个其他类中调用,例如,
class Foo {
@protected
void doSomethingSpecial() {}
}
class Bar {
final foo = Foo();
consumeDoSomethingSpecial() {
foo.doSomethingSpecial();
}
}
可以理解的是,foo.dosomethingspecial()
triggers 在C ++世界中,我会注释
The member 'doSomethingSpecial' can only be used within instance members of subclasses...
栏作为foo的friend
允许此通话,但我没有看到DART中的等效注释吗?
添加上方来抑制警告,但是我没有看到适用于使用@protected
注释的皮棉规则吗?
// ignore: the_appropriate_lint_rule
我确实看到我可以通过在警告上
I'm using the Dart annotation @protected
because I want to limit a member to only be called from a single other class, like so
class Foo {
@protected
void doSomethingSpecial() {}
}
class Bar {
final foo = Foo();
consumeDoSomethingSpecial() {
foo.doSomethingSpecial();
}
}
Understandably, foo.doSomethingSpecial()
triggers the warning
The member 'doSomethingSpecial' can only be used within instance members of subclasses...
In the C++ world I would annotate Bar as a friend
of Foo to permit this call but I'm not seeing the equivalent annotation in Dart?
I did see that I can suppress a warning by adding
// ignore: the_appropriate_lint_rule
above the line with the warning but I'm not seeing a lint rule that applies to using the @protected
annotation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DART中的“朋友”基本上是通过确保标识符为“图书馆 - 局部”(从下划线开始)来实现的,并且所有朋友都在同一库中。 DART中的库通常只是一个文件。但是,使用部分/部分可以跨越多个文件。
任何对下划线假定标识符的引用是同一库的范围内,但即使您导入该文件,也不在其他任何地方的范围。
"friend" in Dart is essentially implemented by ensuring that the identifiers are "library-local" (begin with underscore), and all friends are in the same library. A library in Dart is typically just a single file; however, using part/part-of, it can span multiple files.
Any reference to an underscore-prefixed identifier is in-scope for the same library, but out of scope anywhere else, even if you import that file.