【发布时间】:2020-08-03 17:27:03
【问题描述】:
我有如下功能界面
@FunctionalInterface
public interface Processor { void handle(String text); }
我有办法
doSomething(Processor processor)
我可以像这样调用 doSomething
public class Demo {
public void rockTheWorldTest(String text) {
// Processing
}
}
我可以像下面这样称呼它
doSomething(new Demo::rockTheWorldTest);
但我无法知道特定类中方法的名称,我想使用另一个类的反射来调用它
Method[] testClasMethods = DemoAbstractOrchestratorTest.getClass().getDeclaredMethods();
for (Method method : testClasMethods) {
doSomething(method) // Not able to do this.
}
【问题讨论】:
标签: java reflection functional-interface