[英]What are the type primitives in Dart / Flutter?
I'm expecting a list that has things like String
, Class
, Function
(?) in it.我期待一个包含
String
、 Class
、 Function
(?) 之类的列表。
I can't seem to find this anywhere in the Dart documentation .我似乎在Dart 文档中的任何地方都找不到这个。
Specifically actually right now I'm writing something where I want to pass in a function as a parameter, so I'm trying to figure out what the function/method type is (assuming that is a thing), but more generally I want the reference to all the Dart type primitives.具体来说,实际上现在我正在写一些我想传入 function 作为参数的东西,所以我试图弄清楚函数/方法类型是什么(假设这是一个东西),但更一般地说,我想要参考所有 Dart 类型原语。
Most Dart types are just class/interface types.大多数 Dart 类型只是类/接口类型。 Unlike Java, Dart does not have "primitive" value types that are not interfaces, so in Dart
int
, double
, String
, bool
and Null
normal interfaces which are subtypes of Object?
Unlike Java, Dart does not have "primitive" value types that are not interfaces, so in Dart
int
, double
, String
, bool
and Null
normal interfaces which are subtypes of Object?
(and of Object
except for Null
), and the values are just normal objects. (以及
Object
除了Null
),并且这些值只是普通对象。
Dart does have some types and type constructors which are not class/interface types, or which have specific rules preventing you from implementing them. Dart 确实有一些类型和类型构造函数,它们不是类/接口类型,或者具有阻止您实现它们的特定规则。 In particular:
尤其是:
void
- Equivalent to Object?
void
- 相当于Object?
, but you're not allowed to use the value. void
function, but no-one is supposed to use it.void
function 返回任何值,但不应有人使用它。dynamic
- Equivalent to Object?
dynamic
- 相当于Object?
, but without static type checking. dynamic
, and then use it as any type, and you get run-time errors if you make a mistake.dynamic
,然后将其用作任何类型,如果您犯了错误,则会出现运行时错误。Never
- an empty subtype of all types. Never
- 所有类型的空子类型。 A function returning Never
is guaranteed to throw.Never
的 function 保证会抛出。type Function(argTypes)
- A function type. type Function(argTypes)
- function 类型。 Some values are functions.Function
and Object
.Function
和Object
的子类型。FutureOr<type>
- a supertype of both type
and Future<type>
. FutureOr<type>
- type
和Future<type>
的超类型。type?
- a nullable type. type
and Null
. type
和Null
的超类型。 Then the following interfaces have restrictions which prevents you from implementing them in your own classes: Null
, int
, double
, num
, bool
, String
, and Function
.然后以下接口有限制,阻止您在自己的类中实现它们:
Null
、 int
、 double
、 num
、 bool
、 String
和Function
。
So, for function types, you write them as, fx, int Function(int, {int y})
.因此,对于 function 类型,您可以将它们写为 fx,
int Function(int, {int y})
。
I think this is what you're looking for: dart:core library :我想这就是你要找的: dart:core library :
Built-in types, collections, and other core functionality for every Dart program.
每个 Dart 程序的内置类型、collections 和其他核心功能。
Specifically this part: Classes , where you could find:特别是这部分: Classes ,您可以在其中找到:
String A sequence of UTF-16 code units.
字符串UTF-16 代码单元的序列。 [...]
[...]
Object The base class for all Dart objects.
Object所有 Dart 对象的基础 class。 [...]
[...]
Function The base class for all function types.
Function基础 class 适用于所有 function 类型。 [...]
[...]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.