Skip to content

Files

Latest commit

 

History

History
41 lines (30 loc) · 698 Bytes

prefer_void_to_null.md

File metadata and controls

41 lines (30 loc) · 698 Bytes

Pattern: Use of Null instead of void

Issue: -

Description

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>{};

Further Reading