简体   繁体   English

dart 中的@运算符到底是什么意思?

[英]What does @ operator exactly mean in dart?

I see many instances of @ sign like @package_name or @somthing in dart.我在 dart 中看到了很多@符号实例,例如 @package_name 或 @somthing。 Although I know the usage of some examples like @override , I can't understand why some packages(eg: @freezed ) or dart syntax(eg: @immutable , @lazySingleton ) use this operator and what its functionality is.虽然我知道@override之类的示例的用法,但我不明白为什么某些包(例如: @freezed )或 dart 语法(例如: @immutable@lazySingleton )使用此运算符以及它的功能是什么。

it's metadata read here about it: dart language-tour它的元数据在这里阅读: dart language-tour

As Kherel mentioned, the @ symbol is for metadata.正如 Kherel 提到的,@ 符号用于元数据。 It helps developers keep track of certain functions for future purposes.它可以帮助开发人员跟踪某些功能以备将来使用。

If you want, you can then use that metadata for programmatic purposes using the 'dart:mirrors' library.如果需要,您可以使用“dart:mirrors”库将该元数据用于编程目的。

For example, flutter uses @override to ensure that child classes are allowed their specific behavior, separate from the parents.例如,flutter 使用@override 来确保允许子类的特定行为与父类分开。

The most common usage is to classify functions and classes in some way for easy access.最常见的用法是以某种方式对函数和类进行分类以便于访问。 IDEs may also keep track of certain metadata to warn you about the way functions operate (via @TODO or @deprecated, for instance). IDE 还可以跟踪某些元数据,以警告您函数的运行方式(例如,通过@TODO 或@deprecated)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM