当前位置:网站首页>Function of getinstance() method
Function of getinstance() method
2022-06-25 14:48:00 【Happy Jiajia】
getInstance() The role of methods
getInstance() Refers to instantiation , And new similar , But in new There is a big difference
// Instantiation
public static DBConnect instance;
public static DBConnect getInstance(){
if (instance == null) {
instance = new DBconnect();
}
return instance;
}
getInstance In singleton mode ( Make sure there is only one instance of a class , And provide a global access point to access it ) Common in classes , Used to generate unique instances ,getInstance Tend to be static Of .
Generally used for relatively large 、 Complex objects , Initialize only once , and getInstance It ensures that each call returns the same object .
getInstance() and new The difference between ##
* (1) Object is used through getInstance Get without having to define , You don't need to delete;
* (2)new Be sure to generate a new object , Allocate memory ;getInstance() You don't have to create... Again , It can give you an existing reference , This is better than new;
* (3) new After creation, it can only be used once , and getInstance() Can be used across stack areas , Or remote cross regional use . therefore getInstance() Usually create static Of static instance methods .
边栏推荐
- How to crop GIF dynamic graph? Take this picture online clipping tool
- laravel8实现图片验证码
- The best screenshot tool in the world, color absorption tool snipaste
- ffmpeg protocol concat 进行ts流合并视频的时间戳计算及其音画同步方式一点浅析
- 让PyTorch训练速度更快,你需要掌握这17种方法
- Heavyweight! The domestic IDE is released and developed by Alibaba. It is completely open source! (high performance + high customization)
- Deploy eve-ng with KVM virtualization
- 成员变量与局部变量的区别
- Encapsulating functions and event handling
- 全国首例,中国电信 5G 井下人员定位项目正式商用:可实时跟踪位置,保障作业安全
猜你喜欢

从408改考自主命题,211贵州大学考研改考

Kubernetes understands kubectl/ debugging

多张动图怎样合成一张gif?仅需三步快速生成gif动画图片

电源自动测试系统NSAT-8000,精准高速可靠的电源测试设备

【Try to Hack】vulnhub DC1

定位position(5种方式)

JS to add elements to the header, or tail of an array

From 408 to independent proposition, 211 to postgraduate entrance examination of Guizhou University

API encapsulation of uniapp applet

It's not easy to understand the data consistency of the microservice architecture for the first time after six years as a programmer
随机推荐
JS functions
Output 0 ~ n digits and output multiple times
Is it safe to open an online stock account? Who knows
Thymeleaf Usage Summary
Arithmetic operations and expressions
Supplementary inheritance and strict mode
使用sphinx根据py源文件自动生成API文档
【HBZ分享】LockSupport的使用
Renix perf: detailed explanation of IP network performance test tools and test case parameters
让PyTorch训练速度更快,你需要掌握这17种方法
Using Sphinx to automatically generate API documents from py source files
Vs2019 scanf error
QQ love talk candy love talk content acquisition and storage
Reading the "clean" series for the first time, I didn't think it was a good book
Variables, scopes, and variable promotion
JS get the height and width corresponding to the box model (window.getcomputedstyle, dom.getboundingclientrect)
15 -- 最接近原点的 K 个点
New good friend Pinia, leading the new era of state management
现在股票开户用什么app最安全?知道的给说一下吧
[untitled] the CMD command window displays' NPM 'which is not an internal or external command