比如把 method1 作为 method2 的参数. 可以吗? 如何弄?必须要是abstract method吗?谢谢
解决方案 »
- 现在项目中需要实现在线浏览word excel等文档的功能请问有什么好的实现方法?
- (Annotation)org.hibernate.hql.ast.QuerySyntaxException: XX is not mapped ! 请高手解决
- jsp 如何让图片循环输出
- timer不执行问题
- 求助:hibernate取日期问题(得到前一天)
- 100分求助:ftp下载图片直接显示在jsp,为什么不走下载器提示保存本地?
- 问大家关于javaWeb开发框架中struts2的action的问题。
- 如何指定tomcat使用的jdk,但不在环境变量中设置java_Home
- jsp传数组参数问题?
- 谁能讲一下用jboss+tomcat做EJB时,它们之间的关系,3X
- 用jdbcTemplate插入数据到数据库中,事务提交却无法保存数据
- 搭建安卓环境去哪下载ADT和SDK呢 谁给个最新的下载地址啊 谢谢
但是在定义方法的时候应该不能把method2作为参数,没有具体了解过!
public void setAllComponents(Component[] myComponentArray, Method myMethod) {
for (Component leaf : myComponentArray) {
if (leaf instanceof Container) { //recursive call if Container
Container node = (Container) leaf;
setAllComponents(node.getComponents(), myMethod);
} //end if node
myMethod(leaf);
} //end looping through components
}
invoked such as:setAllComponents(this.getComponents(), changeColor());
setAllComponents(this.getComponents(), changeSize());
http://www.coitweb.uncc.edu/~revesz/Fall2012/NewFix.html作业要求,不知道为啥
这个地方传的参数,第一个是个数组,第二个是个对象(对象名叫Method,不是你理解的method)
我们作业要求:
The purpose of this project is to demonstrate the technique for passing function names (i.e., method names) as parameters to other functions/methods in Java.http://www.coitweb.uncc.edu/~revesz/Fall2012/NewFix.html
public void sayHello() {
System.out.println("hello java!");
} public void foo(String methodName) {
try {
getClass().getDeclaredMethod(methodName).invoke(this);
} catch (Exception e) {
e.printStackTrace();
}
} public static void main(String[] args) {
DemoInvoke di = new DemoInvoke();
di.foo("sayHello");
}}
public class DemoInvoke {
public void sayHello() {
System.out.println("hello java!");
} public void foo(String methodName) {
try {
getClass().getDeclaredMethod(methodName).invoke(this);
} catch (Exception e) {
e.printStackTrace();
}
} public static void main(String[] args) {
DemoInvoke di = new DemoInvoke();
di.foo("sayHello");
}}