What are the semantics of _internal?

The _internal construction is just a name often given to constructors that are private to the class (the name is not required to be ._internal you can create a private constructor using any Class._someName construction).

For example the following code only allows you to create new persons from outside the class using a caching constructor:

class Person {

    final String name;
    static Map<String,Person> _cache;

    factory Person(String name) {
        if(_cache === null) {
            _cache = new Map<String,Person>();
         }
         if(_cache[name] === null]) {
            _cache[name] = new Person._internal(name); 
         }
         return _cache[name];
    }
   
    Person._internal(this.name);
}

In general Dart treats any _construction as private to either the class or the library that contains it. For example you can define as a global function like this:

_globalToThisLibaryOnly() {
    print("can only be called globally within this #library");
}

which can be called from any file that is sourced within the library that defines it.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)