I ' mworkingwiththebasicsofjavareflectionandobservinginformationmethodsofclasses.ineedtogetamethodthatmatchesspecification ion.however,whenidothisigetanosuchmethodexception,andiwashopingyoucouldtellmewhymyimplement
staticvoidmethodinfo2(字符串类名称) throws jzdlm,
Class cls=null;
try{
cls=class.forname(classname );
}catch(JZdlme ) {
e .打印堆栈跟踪(;
}
}
edit 1: when I printout ' cls : ' cls,theoutputis ' cls 3360 class a8. my class2'.whydoesitappendtheclasspart? (the a8 is correct,so don't worry about that )/EDIT1
thisisthefunctioniusetoreadinaclassfrommymainfunction,andtheniwanttogetmethod (使用the参数' test ' and null, where ' test ' isthenameofthemethodandnullmeansthemethodhasnoparameters.theclassiamreadinginiscalledmyclass2which is here 3360
package a8;
公共类my类2 {
voidtest(}
//'takes no parameters '
//'returns bool '
//'name starts with test '
//返回真;
}
}
As you can see,themethoddoesinfactexistintheclass.ifyoucouldpointoutmymistake,I would really appreciate it。
解决方案
makeyourtestmethodpublic.I believe class.get method () is limited to public methods。