当前位置:网站首页>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 .
边栏推荐
- C language escape character and its meaning
- 【世界历史】第一集——石器时代的人们
- Report on Hezhou air32f103cbt6 development board
- Cool assembly tutorial - concise x86 assembly language tutorial (1)
- Clinical chemistry | zhangjianzhong / Xu Jian develop single cell precision diagnosis and treatment technology for Helicobacter pylori
- In 2022, the score line of Guangdong college entrance examination was released, and several families were happy and several worried
- NBD Network Block Device
- Basic usage of markdown (plain text and grammar)
- Uniapp icon configuration
- Kubernetes 理解kubectl/调试
猜你喜欢

Heavyweight! The domestic IDE is released and developed by Alibaba. It is completely open source! (high performance + high customization)

让PyTorch训练速度更快,你需要掌握这17种方法

使用sphinx根据py源文件自动生成API文档

2022年广东高考分数线出炉,一个几家欢喜几家愁

Uniapp icon configuration

How to make GIF animation online? Try this GIF online production tool

JGG | 河北大学杜会龙组综述植物泛基因组学研究

开餐馆
![[untitled] the CMD command window displays' NPM 'which is not an internal or external command](/img/db/b1ae4b0d1110af1e24887ba3b4fe16.jpg)
[untitled] the CMD command window displays' NPM 'which is not an internal or external command

The best screenshot tool in the world, color absorption tool snipaste
随机推荐
Time stamp calculation and audio-visual synchronization of TS stream combined video by ffmpeg protocol concat
Is it safe to open an online stock account? Who knows
Gif动图如何裁剪?收下这个图片在线裁剪工具
如何裁剪动图大小?试试这个在线照片裁剪工具
让PyTorch训练速度更快,你需要掌握这17种方法
分享自己平時使用的socket多客戶端通信的代碼技術點和軟件使用
[Ocean University of China] information sharing for the first and second examinations of postgraduate entrance examination
电源自动测试系统NSAT-8000,精准高速可靠的电源测试设备
Jaspersoft studio installation
Which is better and safer, GF easy gold rush or flush
Page 112 machine learning - review of fundamentals of mathematics pptx
Deploy eve-ng with KVM virtualization
挖财是正规的吗?股票开户安全吗?
For the first time in China, Chinatelecom 5g underground personnel positioning project is officially commercial: it can track the position in real time to ensure operation safety
Mysql database compressed backup_ Summary of MySQL backup compression and database recovery methods
Dmsetup command
How to crop GIF dynamic graph? Take this picture online clipping tool
Position (5 ways)
Biscuit distribution
买基金在哪里开户安全?求指导