Pattern: Use of Null
instead of void
Issue: -
DO NOT use the type Null
where void
would work.
Example of incorrect code:
Null f() {}
Future<Null> f() {}
Stream<Null> f() {}
f(Null x) {}
Example of correct code:
void f() {}
Future<void> f() {}
Stream<void> f() {}
f(void x) {}
Some exceptions include formulating special function types:
Null Function(Null, Null);
and for making empty literals which are safe to pass into read-only locations for any type of map or list:
<Null>[];
<int, Null>{};