Darth 2: Difference Between Future <void> and Future <Null>

Having an asynchronous function that does not return a value, what type of return type is Future<Null> or Future<void> ?, Or more specifically, what is the difference in usage? Both are legal, and in both cases the return value of the function is Future , which resolves to null . The following code prints null twice:

 import 'dart:async'; Future<void> someAsync() async {} Future<Null> otherAsync() async {} main() { someAsync().then((v) => print(v)); otherAsync().then((v) => print(v)); } 
+5
source share
1 answer

Null Type Only Null

The void type accepts values ​​of any type, but indicates that the value should not be used.

It is not clear to me how support for void tools will be supported. There will probably be linter rules that prompt or warn when using void values.

Null previously used instead of void because void was only supported as a return type of methods / functions.

+6
source

Source: https://habr.com/ru/post/1276008/


All Articles