当前位置:网站首页>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 .
边栏推荐
- [Ocean University of China] Data Sharing for retest of initial Examination
- Deconstruction assignment of variables
- The best screenshot tool in the world, color absorption tool snipaste
- 2022年广东高考分数线出炉,一个几家欢喜几家愁
- 多张动图怎样合成一张gif?仅需三步快速生成gif动画图片
- API encapsulation of uniapp applet
- 【世界历史】第二集——文明的曙光
- Golang project dependency management tool go vendor, go Mod
- Heavyweight! The domestic IDE is released and developed by Alibaba. It is completely open source! (high performance + high customization)
- 【中國海洋大學】考研初試複試資料分享
猜你喜欢
Complete and detailed compilation of experimental reports
Heavyweight! The domestic IDE is released and developed by Alibaba. It is completely open source! (high performance + high customization)
Power automatic test system nsat-8000, accurate, high-speed and reliable power test equipment
Stream竟然还有应用进阶学习?作为程序员的你知道吗
15 -- k points closest to the origin
Time stamp calculation and audio-visual synchronization of TS stream combined video by ffmpeg protocol concat
Application of TSDB in civil aircraft industry
Gif动画怎么在线制作?快试试这款gif在线制作工具
JGG | 河北大学杜会龙组综述植物泛基因组学研究
Gif动图如何裁剪?收下这个图片在线裁剪工具
随机推荐
有哪个瞬间让你觉得这个世界出bug了?
Mutationobserver listens for DOM changes
dmsetup命令
Extend JS copy content to clipboard
How to view the Chrome browser plug-in location
[Ocean University of China] Data Sharing for retest of initial Examination
中国电池技术取得重大突破,日韩美都落后了,中国巩固了领先优势
Where is it safe to open an account for buying funds? Ask for guidance
Laravel8 implementation of picture verification code
Application of TSDB in civil aircraft industry
[HBZ sharing] use of locksupport
Report on Hezhou air32f103cbt6 development board
Go语言Zap库Logger的定制化和封装使用详解
Encapsulating functions and event handling
全国首例,中国电信 5G 井下人员定位项目正式商用:可实时跟踪位置,保障作业安全
Add a string at the input and textarea cursors
Renix perf: detailed explanation of IP network performance test tools and test case parameters
Cool assembly tutorial - concise x86 assembly language tutorial (1)
[world history] Episode II: Dawn of civilization
Two methods to rollback the code in pycharm to the specified version (with screenshot)