简体   繁体   English

什么是线程安全以及 const 构造函数和最终成员(不可变类)如何在 Dart 中实现“线程安全”?

[英]What is Thread Safety and how const constructor and final members (Immutable class) achieve "Thread-safety" in Dart?

What is the point of writing this immutable class and normal class and how it is thread safe?写这个不可变的 class 和普通的 class 有什么意义,它是线程安全的吗?

class SomeClass{
  final String name;
  
  const SomeClass(this.name); 
  
}

class SomeClass2{
  String name;
  
  SomeClass2(this.name);
}

Dart is a single thread programming language because it's been developed to compile Javascript which is also a single thread programming language so it is not about that. Dart是一种单线程编程语言,因为它是为编译Javascript而开发的,Javascript 也是一种单线程编程语言,所以与此无关。 If we were to consider your second question it is little bit complex so you can check this for an answer .如果我们要考虑你的第二个问题,它有点复杂,所以你可以检查这个以获得答案

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

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