Is it possible to have a private constructor in dart?

后端 未结 2 920
清歌不尽
清歌不尽 2021-02-06 22:01

I\'m able to do something like the following in TypeScript

class Foo {
  private constructor () {}
}

so this constructor is access

2条回答
  •  鱼传尺愫
    2021-02-06 22:32

    Just create a named constructor that starts with _

    class Foo {
      Foo._() {}
    }
    

    then the constructor Foo._() will be accessible only from its class (and library).

提交回复
热议问题