What do people use class loading for?

前端 未结 18 1466
暗喜
暗喜 2021-02-02 14:26

So, every Java text book talks about how flexible Java is since it can load classes at run time. Just cobble together a string and give it to Class.forName(), and

18条回答
  •  粉色の甜心
    2021-02-02 15:18

    Servlet containers like Tomcat read your war/webapp configuration file from WEB-INF/web.xml and load your Servlet/Filter/etc. subclasses based on the String values you put in the XML file. For database connections, they pull the class name to load from your configuration, e.g. "com.mysql.jdbc.Driver" for MySQL.

提交回复
热议问题