Is it possible to have a private constructor in dart?

后端 未结 2 919
清歌不尽
清歌不尽 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:20

    A method without any code must be something like this

    class Foo {
      Foo._();
    }
    
    0 讨论(0)
  • 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).

    0 讨论(0)
提交回复
热议问题