As a complete beginner learning Dart
, I want to understand if the void
type is required for a main
function. In the official language tour: https://dart.dev/guides/language/language-tour#a-basic-dart-program the examples do not include the void
keyword/type.
But in other places we seed void main() {
...
The following two snippets of code have the same output:
main() {
print('Hello World!');
}
Runs fine on Dart Pad: https://dartpad.dartlang.org/fa6f6e5a7b9406e88b31a17e82655ef8
(we don't see any compiler warnings or advice suggesting the void
should be added)
void main() {
print('Hello World!');
}
Is the void
a convention that nobody questions or can we exclude it without any consequences?
Note: I'm aware of the history of void
keyword/type, I just want to understand if I can safely omit the void
from more advanced programs or if it's required.