Class.forName() and ClassLoader.loadClass()

Class. forName(String className) throws ClassNotFoundException
Returns the Class object associated with the class or interface with the given string name. Invoking this method is equivalent to:
  Class.forName(className, true, currentLoader)
 
當調用這個方法的時候, 將會完成類的初始化工作.

 

這也是jdbc 應用中常見的, Class.forName("... driver");

 

ClassLoader.loadClass(); 不會做類的初始化工作,只是將class load到jvm中.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章