Add Your Heading Text Here

A Symbol object represents an operator or identifier declared in a Dart program.

Simply symbol is a mechanism for retrieving metadata of different identifiers.

For ex :

void main(){
// create an identifier or symbol for “Sample” in memory.
 Symbol test =new Symbol("sample");
 print(test);
 print(#test);
// add “#” to create a symbol literal for any object(here, 
 random value xyz).
 print(#xyz);
}

Output :

Symbol(“sample”)
Symbol(“test”)
Symbol(“xyz”)

The symbols are the references created for different identifiers in the program.

Symbol literals(prefixing any identifier with # symbol) are compile time constants.

But, symbols are invaluable for APIs that refer to identifiers by name, because minification changes identifier names but not identifier symbols.

Probably you might never need to use symbols. But, we have introduced symbol for shake hand purpose with dart.

Previously, symbols were supported by different predefined classes like MirrorSystem. But, currently they all are deprecated. So, it’s better to just learn about symbols and move on.

Feel free to ask your questions in the comment section. Keep reading and commenting your suggestions to make toastguyz a better site to learn different programming languages.

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Sagar Shah
Sagar Shah
3 years ago

well

Show Buttons
Hide Buttons