Class.forName:返回与给定的字符串名称相关联类或接口的Class对象。Class.forName是一个静态方法,同样可以用来加载类。
classforname的形式
该方法有两种形式:Class.forName(Stringname,booleaninitialize,ClassLoaderloader)和Class.forName(StringclassName)。第一种形式的参数name表示的是类的全名;initialize表示是否初始化类;loader表示加载时使用的类加载器。第二种形式则相当于设置了参数initialize的值为true,loader的值为当前类的类加载器。
staticClass<?>
forName(StringclassName)
ReturnstheClassobjectassociatedwiththeclassorinterfacewiththegivenstringname.
staticClass<?>
forName(Stringname,booleaninitialize,ClassLoaderloader)
ReturnstheClassobjectassociatedwiththeclassorinterfacewiththegivenstringname,usingthegivenclassloader.
classforname的说明:
publicstaticClass<?>forName(StringclassName)
ReturnstheClassobjectassociatedwiththeclassorinterfacewiththegivenstringname.Invokingthismethodisequivalentto:
Class.forName(className,true,currentLoader)
wherecurrentLoaderdenotesthedefiningclassloaderofthecurrentclass.
Forexample,thefollowingcodefragmentreturnstheruntimeClassdescriptorfortheclassnamedjava.lang.
总之,classforname给大家简单的介绍了一些,希望大家多看看。