当前位置:网站首页>GenericServlet为什么有两个init方法
GenericServlet为什么有两个init方法
2022-07-27 03:39:00 【散散汪】
init(ServletConfig config)负责初始化config对象,次方法调用了init() 后者没有任何实现,后者的作用是让开发者在继承此类的时候重写init()方法,不要继承init(ServletConfig config),从而避免了因为没有调用super.init(config)而没有对config初始化。
只要我们复写无参的init方法,tomcat在调用完有参的init方法时调用无参的init方法,这样两个操作都执行了。而且我们也不用写super.init();试想一下,如果没有无参的init方法,那我们复写有参的init方法时忘记了些super.init(config)方法,那么config就不能初始化了,而这样设计即使我们不调用super的方法,也不会出问题。何乐而不为呢!
反正就是套娃
边栏推荐
猜你喜欢

Practice of microservice in solving Library Download business problems

e.target与e.currentTarget的区别

Session&Cookie&token

js修改对象数组的key值

微信小程序轮播图

influxDB 基础了解

list模拟实现

Stm32cubemx learning notes (41) -- eth interface +lwip protocol stack use (DHCP)

356 pages, 140000 words, weak current intelligent system of high-end commercial office complex, 2022 Edition

HEAD detached from origin/...导致push失败
随机推荐
Remember the major performance problems caused by a TCP packet loss
What is animation effect? What is the transition effect?
Subject 3: Jinan Zhangqiu line 3
Rust:axum learning notes (1) Hello World
卷积神经网络——灰度图像的卷积
Specified interval inversion in the linked list
Subject 3: Jinan Zhangqiu line 6
JS to realize page Jump and parameter acquisition and loading
大咖说·图书分享|精益产品开发:原则、方法与实施
The new Internet era has come. What new opportunities will Web 3.0 bring us
php+swoole
记一次TCP丢包带来的重大性能问题
[Code] sword finger offer 04 search in two-dimensional array
Redis面试题(2022)
Leetcode daily question: relative sorting of arrays
Leetcode:433. minimal genetic change
【比赛参考】PyTorch常用代码段以及操作合集
[machine learning network] BP neural network and deep learning-6 deep neural networks (DNN)
Sum of binary numbers from root to leaf
webpack打包vue项目添加混淆方式,解决缓存问题