当声明为常数时,为什么高度和宽度会提供默认值? [英] why is height and width when declared as a constant gives the default value?

查看:59
本文介绍了当声明为常数时,为什么高度和宽度会提供默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将heightwidth用作常量时,我​​想知道为什么它赋予我值100?是因为上面没有声明size();吗?如何将其设置为画布的大小?因为以下打印100

When I use the height and width as a constant I was wondering why it's giving me the value 100? Is it because size(); was not declared above? How do I set it to the size of the canvas? Because the following prints 100

任何帮助都可以!!

这是我的代码的副本:

final int SIZE = height;

void setup() {
 size (1000,1000);
 println(SIZE); 

}

推荐答案

对于基本类型,值本身存储在变量中. 因此,当您调用final int SIZE = height;时,SIZE将具有height在该分配之前立即具有的值. height的所有后续更改都不会影响SIZE.

For primitive types the value itself is stored in a variable. So when you call final int SIZE = height; SIZE will have the value which height had immediately prior to that assignment. All subsequent changes to height will not affect SIZE.

这篇关于当声明为常数时,为什么高度和宽度会提供默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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