编译时间常数和运行时间常数有什么区别 [英] What is the difference between compile time constant and run time constant

查看:64
本文介绍了编译时间常数和运行时间常数有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我理解时会怀疑,Dart语言中的编译时常数和运行时常数,我是dart语言的初学者,我在google中搜索到没有涉及此问题的文章,所以在此先感谢

I have Doubt when understand, Compile-time constant and runtime constant in Dart language, I am a beginner in dart language, I searched in google there is no article that covers this question, So thanks in advance

推荐答案

Dart中没有运行时常量",而不是通常使用常量"一词的方式.所有常量都是编译时常量,这意味着它们的整个值可以在编译时确定,它们是高度不变的,并且如果两个常量,则编译器可以规范化对象表达式最终以状态完全相同的对象结束.

There are no "run-time constants" in Dart, not the way the word "constant" is generally used. All constants are compile-time constants, meaning that their entire value can be determined at compile-time, they are deeply immutable, and the compiler can canonicalize the objects if two constant expressions end up with objects that have the exact same state.

编译时常量"一词的名称来自规范,该规范讨论了编译时常量表达式".这些表达式的结果仅称为常量".

The name "compile-time constants" wording comes from the specification which talks about "compile-time constant expressions". The results of those expressions are just called "constants".

您可以说 final x = List< int> .unmodifiable([1]); 定义了一个常数.它肯定是一个不能修改的对象,但是在Dart术语中却不是传统上称为 constant 的对象-不能在语言需要恒定值的地方使用.

You can say that final x = List<int>.unmodifiable([1]); defines a constant. It's certainly an object which cannot be modified, but it's not what would traditionally be called a constant in Dart terminology - it cannot be used in the places where the language requires a constant value.

这篇关于编译时间常数和运行时间常数有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆