Skip to content

Introduce a shorthand syntax to reuse ancestor constructors without having to duplicate the signature #22274

@Hixie

Description

@Hixie

I have an abstract class with the following constructor. It has 5 subclasses, each of which should have that exact same constructor. For reasons that I hope are obvious, I don't really want to have to write out that whole signature six times, plus 5 occurrences of referencing the superclass constructor listing all the arguments...

abstract class PointerEvent extends Event {
    PointerEvent({ bool bubbles,
                                  this.pointer,
                                  this.kind,
                                  this.x, this.y,
                                  this.dx: 0.0, this.dy: 0.0,
                                  this.buttons: 0,
                                  this.down: false,
                                  this.primary: false,
                                  this.obscured: false,
                                  this.pressure, this.minPressure, this.maxPressure,
                                  this.distance, this.minDistance, this.maxDistance,
                                  this.radiusMajor, this.radiusMinor, this.minRadius, this.maxRadius,
                                  this.orientation, this.tilt
                              }): super(bubbles: bubbles);
    // ...lots of final fields...
}

Lasse suggests allowing a shorthand syntax for declaring constructors that just redirect to the superclass:

abstract class PointerDownEvent extends PointerEvent {
    PointerDownEvent = super;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).core-mtype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions