Skip to content

Latest commit

 

History

History
44 lines (32 loc) · 591 Bytes

prefer_const_constructors.md

File metadata and controls

44 lines (32 loc) · 591 Bytes

Pattern: Missing use of const constructor

Issue: -

Description

If a const constructor is available, it is preferable to use it.

Example of correct code:

class A {
 const A();
}

void accessA() {
 A a = const A();
}

Example of correct code:

class A {
 final int x;

 const A(this.x);
}

A foo(int x) => new A(x);

Example of incorrect code:

class A {
 const A();
}

void accessA() {
 A a = new A();
}

Further Reading