2011-10-06 38 views
2

閱讀Tomcat 7源代碼,我只是想知道Tomcat實例Catalina爲什麼通過使用反射而不是簡單地使用new創建對象並直接調用方法來調用相關方法?爲什麼Tomcat使用反射來實現Catalina instancilization

+1

您能向我們提供相關的源代碼? –

+6

在不相關的新聞:我真的很喜歡「instancilization」這個詞,並試圖使它成爲我活躍詞彙的一部分。 –

+0

看到這個:類 startupClass = catalinaLoader.loadClass (「org.apache.catalina.startup.Catalina」); Object startupInstance = startupClass.newInstance(); –

回答

3

答案是在Bootstrap類的javadoc註釋:

/** 
* Bootstrap loader for Catalina. This application constructs a class loader 
* for use in loading the Catalina internal classes (by accumulating all of the 
* JAR files found in the "server" directory under "catalina.home"), and 
* starts the regular execution of the container. The purpose of this 
* roundabout approach is to keep the Catalina internal classes (and any 
* other classes they depend on, such as an XML parser) out of the system 
* class path and therefore not visible to application level classes. 
* 
* @author Craig R. McClanahan 
* @author Remy Maucherat 
* @version $Id: Bootstrap.java 1142323 2011-07-02 21:57:12Z markt $ 
*/ 

public final class Bootstrap { ... } 
相關問題