简体   繁体   English

如果一个集合文字是集合类型,那么它在 dart 中的 class 是什么?

[英]If a set literal is of type set then what is its class in dart?

So the following code snippet所以下面的代码片段

Set mySet = {1,2,3};

is an instance of type Set which is permissible, however what would the class of the set literal be.是允许的 Set 类型的实例,但是集合文字的 class 会是什么。 I have tried to search for this, however I have found no answer in the dart documentation.我试图搜索这个,但是我在 dart 文档中没有找到答案。

A literal exists only in your source code.文字只存在于您的源代码中。 Asking for its "class" doesn't make a lot of sense.要求它的“类”没有多大意义。

Using a Set , Map , or List literal is just syntactic sugar for invoking a corresponding constructor.使用SetMapList文字只是调用相应构造函数的语法糖。 The Set factory constructor constructs a LinkedHashSet . Set工厂构造函数构造一个LinkedHashSet

However, you'll see that LinkedHashSet is also abstract.但是,您会看到LinkedHashSet也是抽象的。 Its factory constructor returns an instance of a private, internal class.它的工厂构造函数返回一个私有的内部 class 的实例。 You can see its typename via print(Set().runtimeType) ;你可以通过print(Set().runtimeType)看到它的类型名; the actual type might be different for different platforms and is unlikely to be useful to you.对于不同的平台,实际类型可能会有所不同,并且不太可能对您有用。

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

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