How do I call a super constructor in Dart?

前端 未结 4 1928
难免孤独
难免孤独 2020-12-25 09:35

How do I call a super constructor in Dart? Is it possible to call named super constructors?

4条回答
  •  遥遥无期
    2020-12-25 09:42

    Can I call a private constructor of the superclass?

    Yes, but only if the superclass and the subclass you are creating are in the same library. (Since private identifiers are visible across the whole library they are defined in). Private identifiers are those that start with underscore.

    class Foo {    
      Foo._private(int a, int b) {
        //Code of private named constructor
      }
    }
    
    class Bar extends Foo {
      Bar(int a, int b) : super._private(a,b);
    }
    

提交回复
热议问题