Class.forName("org.gjt.mm.mysql.Driver").newInstance();
时间:2011-11-18
来源:互联网
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
和
Class.forName("org.gjt.mm.mysql.Driver")
有什么区别呢?
;
作者: sanjiuailuoluo 发布时间: 2011-11-18
Class.forName("org.gjt.mm.mysql.Driver")
可以导致加载类,返回值是Class类对象
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
除了导致加载类,还会生成相应的Driver对象事例,即返回值是Object对象(实际上是Driver对象)
可以导致加载类,返回值是Class类对象
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
除了导致加载类,还会生成相应的Driver对象事例,即返回值是Object对象(实际上是Driver对象)
作者: qybao 发布时间: 2011-11-18
为什么需要Class.forName("org.gjt.mm.mysql.Driver")呢?看org.gjt.mm.mysql.Driver里的static块
作者: ticmy 发布时间: 2011-11-18
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.
创建这个Class对象所表示的类的新实例。会被重新实例化,如果未初始化就还会被初始化。(貌似还有forName后未被初始化的情形啊)
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.
创建这个Class对象所表示的类的新实例。会被重新实例化,如果未初始化就还会被初始化。(貌似还有forName后未被初始化的情形啊)
作者: dracularking 发布时间: 2011-11-18
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28