java数据库部分的class.forName()中,里面的参数谁能讲一下?

zhang_wei_question 2002-03-22 04:45:33
java数据库部分的class.forName()中,里面的参数谁能讲一下?
...全文
68 点赞 收藏 7
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
北极猩猩 2002-03-22
简单的说里面是你想要建立实例的类的名称
回复
skyyoung 2002-03-22
Q: Difference between loading and instantiating a class???
Well, the subject says it all. What is the difference between loading and instantiating
a class in a JVM.
Second question: What would happen if at runtime I update a class file? Will the JVM know
to use that instead?
Answer: The difference is that when a class is loaded by a ClassLoader it is read in
as a stream of bytes, presumably from a file, but it could just as easily be from over
the network, and then processed or "cooked" into a representation that the VM can
use to make instances of Objects of that classes type. This last part is the
instantiation. You can load a class at runtime with:
Class.forName( "MyClass" );
and instantiate one with:
MyClass mc = Class.forName( "MyClass" ).newInstance();
Cool, ehh. You don't have to know the name of a class at compile time.
>Second question: What would happen if at runtime I update a class file?
>Will the JVM know to use that instead?
Loaded classes are cached because it's quite costly to do the "cooking" I mentioned
above. So it will not be loaded. You may create a separate ClassLoader with new
SecureClassLoader but that will cause all classes _it_ loads to be loaded from this
new ClassLoader but that's not what
you want.
I don't know if you can specify that a class should be loaded from disk again using
the normal ClassLoader. You could very easily make your own ClassLoader in which
case you would have explicit control over such things. Look at java.lang.ClassLoader and java.lang.Class.
General Java Questions III
回复
GJA106 2002-03-22
也许这个对你有用:
http://www.javageeks.com/Papers/ClassForName/ClassForName.pdf
回复
看了,还是不明白
回复
skyyoung 2002-03-22
http://developer.java.sun.com/developer/qow/archive/114/index.html
回复
wafer_w 2002-03-22
看帮助文档
回复
zha1977 2002-03-22
forName(String className)
className是你要装载的类的名称

forName(String name, boolean initialize, ClassLoader loader)
name也是你要装载的类的名称
loader是你指定的类装载器
回复
相关推荐
发帖
非技术区
创建于2007-09-28

2.3w+

社区成员

Java 非技术区
申请成为版主
帖子事件
创建了帖子
2002-03-22 04:45
社区公告
暂无公告