Some day before, I began to read the source code of the tomcat
First, the server starts from the main method in the org.apache.catalina.startup.BootStrap, but when I go into the code bootstrap.init()
,
and I was confused by the following code.Like:
Just for easy to debug the tomcat, I change the code like this:
The code can still work. And in the Tomcat source code, there are many code block like this, For example,in org.apache.catalina.startup.BootStrap.start()
we can find the following code:
Still for easy to debug, I turn the code into:
The code still works fine.So I was confused, Here are my questions.
- what’s difference between the two kinds of code?
- Why the coder of Tomcat do not write the code like what I write? what’s the benefit?
- If the Tomcat with my kind code works in a production environment, what will happen or nothing will happen?
Any answers or advice should be grateful.
I am thankful that I discovered this weblog, exactly the right info that I was searching for!
为什么要用反射呢,在知道类名和方法名的情况下这样做的意义是什么
@ming:我对此的理解是,假如我们有两个程序员,一个在写程序的时候,需要使用第二个人所写的类,但第二个程序员并没完成他所写的类。那么第一个人的代码不能通过编译。利用Java反射的机制,就可以让第一个程序员在没有得到第二个程序员所写的类的时候,来完成自身代码的编译。