当前位置:网站首页>定义方法时为什么使用static关键字
定义方法时为什么使用static关键字
2022-07-26 06:19:00 【小蚂蚁hjk】
首先说下静态方法的好处:
使用了static关键字的方法后,该方法是在类加载的时候一起加载到内存中的并且只加载一次
使用的时候只需要通过类名就可以访问,不需要再次消耗资源去创建
那么是什么时候结束呢,直到程序结束后该内存才会释放
如果创建方法的时候不适用static关键字会怎么样
如果创建的方法没有被static修饰时该方法的存货时长随着调用开始和调用之后结束,并且结束后直接被JVM回收
其次:
什么时候使用static
如果这个方法是作为一个工具类进行使用的,就声明为static,不需要new一个队形使用了
平常开发中定义的私有方法还是不需要声明为static的
边栏推荐
- A tool for quickly switching local host files -- switchhosts
- Leetcode 42. rainwater connection
- Multi target detection
- If I want to listen to Jay Chou with you, I want you to listen to my whole youth
- 【无标题】
- Leetcode:741. picking cherries
- 时序动作定位 | 用于弱监督时态动作定位的细粒度时态对比学习(CVPR 2022)
- [Hangzhou][15k-20k] medical diagnosis company recruits golang development engineers without overtime! No overtime! No overtime!
- 【Day03_0420】C语言选择题
- Distributed | practice: smoothly migrate business from MYCAT to dble
猜你喜欢

CV (1)- Introduction

VRRP principle and basic commands

Sequential action localization | fine grained temporal contrast learning for weak supervised temporal action localization (CVPR 2022)

What is the concept and purpose of white box testing? And what are the main methods?

Convolutional neural network (III) - target detection

【pytorch】微调技术

TPS Motion(CVPR2022)视频生成论文解读

Flex layout

递归处理——子问题

多目标检测
随机推荐
Modifiers should be declared in the correct order
RNN循环神经网络
Excitation method and excitation voltage of hand-held vibrating wire vh501tc acquisition instrument
[day05_0422] C language multiple choice questions
Leetcode:741. picking cherries
Optical quantum milestone: 3854 variable problems solved in 6 minutes
Recursive processing - subproblem
[day06_0423] C language multiple choice questions
英语句式参考纯享版 - 状语从句
[2023 Jerry technology approval test questions in advance] ~ questions and reference answers
Implementation of PHP multitask second timer
【Day_06 0423】把字符串转换成整数
How can machinery manufacturing enterprises do well in production management with the help of ERP system?
英语句式参考纯享版 - 定语从句
Matlab 向量与矩阵
[day02_0419] C language multiple choice questions
时序动作定位 | 用于弱监督时态动作定位的细粒度时态对比学习(CVPR 2022)
Map集合继承结构
nuxt 配置主题切换
Xiao He shows his sharp corners and says hello to flutter app