请问谁可以详细解释一下java中的reflection? 看看Thinking in JAVA 吧。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 相当有用的东西, rmi中用得很多 ,比如method.invoke 等于c++中的函数指针. Java Reflection API可以检查运行时的对象和动态更新字段与调用方法。尽管日常应用编程中时也使用反射,但更多还是用在中间件工具部分。例如,TOPLink数据库映射工具用反射将数据库值复制到JAVA对象,或将JAVA对象值复制到数据库反射使用起来并不太难而且相当强大。 不过,在程序代码中大量使用反射操作会降低系统的性能,但JDK1。4在这方面有了明显的提高。举个例子给你吧:public Student getGradStudent(int studentNumber){ if(studentNumber >= 1 && studentNumber <=100) { //use reflection to determine if its a GradStudent Class c =students.elementAt(studentNumber).getClass(); if(c.getName().equals("GradStudent")) return (GradStudent) Students.elementAt(studentNumber); } else{ Student tempStudent = (Student) students.elementAt(studentNumber); System.out.println("Student number" + studentNumber + "," + tempStudent.getName() + ", is not a graduate Student."); return null; }} OK,我的理解就是java因为是种动态语言,它可以在运行时期动态装载类型---通过类装载器这点和c++不一样,c++类型在编译时期就要决定,所以它可以做很多优化,那些typelist就是这样思想的产物,包括mpl这些.....不知道我这样理解对否? 请问接口的所有方法都要重写吗? 关于java中string传值问题 为什么命令行的字符串(String)参数,无论有无引号,输出效果等同? 求JAVA中CRC16校验码例子! 当java类中的方法不加任何public等访问控制字眼时,默认是什么访问权限? 怎么通过STRUTS,打开页面时就判断SESSION中的内容有没有?? 关于jar 这个问题挺难的 如何让数据写入txt文件而不是覆盖文件? 如何将Ext正则表达式转换为Java正则表达式 有个数学计算的JAVA代码各位大哥看看帮帮忙 求助 RandomAccessFile 写入中文出现乱码的问题
Java Reflection API可以检查运行时的对象和动态更新字段与调用方法。尽管日常应用编程中时也使用反射,但更多还是用在中间件工具部分。例如,TOPLink数据库映射工具用反射将数据库值复制到JAVA对象,或将JAVA对象值复制到数据库反射使用起来并不太难而且相当强大。
不过,在程序代码中大量使用反射操作会降低系统的性能,但JDK1。4在这方面有了明显的提高。
举个例子给你吧:
public Student getGradStudent(int studentNumber)
{
if(studentNumber >= 1 && studentNumber <=100)
{
//use reflection to determine if its a GradStudent
Class c =students.elementAt(studentNumber).getClass();
if(c.getName().equals("GradStudent"))
return (GradStudent)
Students.elementAt(studentNumber);
}
else{
Student tempStudent = (Student) students.elementAt(studentNumber);
System.out.println("Student number" + studentNumber + "," +
tempStudent.getName() + ", is not a graduate Student.");
return null;
}
}
这点和c++不一样,c++类型在编译时期就要决定,所以它可以做很多优化,那些typelist就是这样思想的产物,包括mpl这些.....
不知道我这样理解对否?