The use of this
is optional except when redirecting to a named constructor, and when it’s needed to distinguish between property names
and arguments or other variables. For the sake of brevity, this
should be omitted when it’s not strictly required.
Noncompliant code example
class Car {
int color;
Car(this.color); // Mandatory to distinguish between 'color' property and 'color' parameter
void fade() {
this.color--; // Noncompliant
}
}
Compliant solution
class Car {
int color;
Car(this.color); // Mandatory to distinguish between 'color' property and 'color' parameter
void fade() {
color--;
}
}