When a library name is prefixed with a '_' it becomes private to its library. How does the dart vm actually implement this privacy?
Internally, the VM suffixes the variable name with a string that is unique to the library, so _foo
might become _foo@1238fa12
. The @
ensures that it can't collide with a user variable because @
isn't valid in a normal identifier. After appending the string, the VM can treat the variable as a completely normal variable, and because there is no other library that can possibly have a reference to the variable, it is effectively library private (although there are probably a few corner cases where it needs to be more clever about private names).
That's not the only possible implementation strategy, but private variables were designed from the beginning to make this strategy possible.