简体   繁体   English

Flutter(Dart) 中方法的默认返回类型是什么?

[英]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 ?如果我没有在 Flutter 的方法中写任何返回类型,那么哪个是默认返回类型? For Example例如

getMyValue(){

}

默认返回类型是dynamic

In general, the type of something that isn't explicitly specified and that isn't inferred is dynamic .通常,未明确指定且未推断的事物的类型是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.如果你有疑问,如果输入一些代码https://dartpad.dartlang.org/ ,移动标识符旁边的文本光标会告诉你它是什么。

First, it tries to infer the type, and only if it fails it uses the dynamic type.首先,它尝试推断类型,并且只有在失败时才使用dynamic类型。 Please read the docs on Type inference请阅读有关类型推断的文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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