首页 > 编程知识 正文

java反射有什么用,java的反射机制是怎么实现的

时间:2023-05-04 16:13:23 阅读:25662 作者:686

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。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。