Class.forName("org.gjt.mm.mysql.Driver").newInstance(); 除了导致加载类,还会生成相应的Driver对象事例,即返回值是Object对象(实际上是Driver对象)
------解决方案-------------------- 为什么需要Class.forName("org.gjt.mm.mysql.Driver")呢?看org.gjt.mm.mysql.Driver里的static块
------解决方案-------------------- public static Class<?> forName(String className) throws ClassNotFoundException Returns the Class object associated with the class or interface with the given string name.
看方法返回类型Class,与className所表示的类或接口关联
public T newInstance() throws InstantiationException, IllegalAccessException Creates a new instance of the class represented by this Class object. The class is instantiated as if by a new expression with an empty argument list. The class is initialized if it has not already been initialized.