当前位置:网站首页>In-depth analysis of the initialization of member variables and local variables
In-depth analysis of the initialization of member variables and local variables
2022-08-02 06:58:00 【work hard and work hard c.】
1. Member variables
Member variables can be initialized without explicit initialization, because the virtual machine assigns a default value to it.
Because the member variables are part of the instance object, and all the instance objects are allocated in the heap memory, when the storage space is allocated in the virtual machine, the member variables of the memory space of the instance object are all allocated.Default initialization, so member variables have value even if you don't explicitly initialize them (the default value for primitive data types is 0, and the default value for reference data types is Null).
2. Local variables
Local variables must be initialized, otherwise they cannot be used.
First of all, local variables are located in the method, and each method is placed in the stack of the runtime data area during the execution of the JVM, and each stack stores the local variable table, operand stack, method exit, dynamic links, etc.Because the memory space required by the local variable table is fixedly allocated during compilation, before the method is called (that is, before the method is pushed onto the stack), it is necessary to determine how much variable space the method stack needs to allocate.It will not change the size of the local variable table, so it means that local variables must be initialized when they are created to determine the size of the allocated memory.
边栏推荐
- Nacos database configuration
- node安装及环境配置
- HCIP BGP Comprehensive Experiment Establishing peers, route reflectors, federation, route announcement and aggregation
- pl/sql之神奇的嵌套与变量生命周期
- zabbix自动发现和自动注册
- MySQL 5.7 installation tutorial (full-step, nanny-level tutorial)
- [OpenCV from entry to practice] image processing technology [pixel] (the most detailed in the whole network)
- Home NAS server (4) | MergerFS and SnapRaid data backup
- 金蝶国际:半年亏掉去年一年,疯狂烧钱的商业模式如何持续
- 触发器简单解释
猜你喜欢
随机推荐
HCIP BGP Comprehensive Experiment Establishing peers, route reflectors, federation, route announcement and aggregation
Analysis of the source code of the JS UI framework of Hongmeng system
MySQL driver jar package download -- nanny tutorial
MySQL(3)
HCIP 第一天
love
Py之mlxtend:mlxtend库的简介、安装、使用方法之详细攻略
leetcode-318.最大单词长度乘积
Not annotated parameter overrides @NonNullApi parameter
nodejs的安装和全局配置(超详细哦)
MySQL union query (multi-table query)
The international top conference OSDI included Taobao system papers for the first time, and the device-cloud collaborative intelligence was recommended by the keynote speech of the conference
A list of 300+ learning resources compiled by senior engineers of the Tao Department (the latest version in 2021)
npm、cnpm的安装
The virtual reality real estate display system foresees the future decoration effect in advance
Double for loop case (use js jiujiu printing multiplication table)
Toolbox App 1.25 新功能一览 | 版本更新
An advanced method for solving palindromes
MySQL database video tutorial from beginner to proficient
Home NAS server (4) | MergerFS and SnapRaid data backup









