简体   繁体   中英

What is a default return type of method in Flutter(Dart)?

If I don't write any return type in method of Flutter then which is default return type ? For Example

getMyValue(){

}

默认返回类型是dynamic

In general, the type of something that isn't explicitly specified and that isn't inferred is dynamic .

Examples:

var x; // Same as `dynamic x`
List listOfDynamic; // Same as `List<dynamic>`
var anotherListOfDynamic = [];
var mapOfDynamicToDynamic = {}; // Same as `Map<dynamic, dynamic>`

foo(x) { } // Same as `dynamic foo(dynamic x)`

If you're in doubt, if enter some code https://dartpad.dartlang.org/ , moving the text cursor next to an identifier will tell you what it is.

First, it tries to infer the type, and only if it fails it uses the dynamic type. Please read the docs on Type inference

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM