クラス内のメソッドの数が変わる可能性があるため、コードを別のメソッドに送信する必要があるため、リフレクションを使用します。benchmarkMethods.get(i).invoke(set, null);しかし、問題は、匿名クラスが最終変数しか渡せない可能性があるため、ループでそれらを列挙できないことです。この場合、どうすればよいですか?
public void RunAllBenchmarks(final Object set, boolean randomOrder) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    final List<Method> benchmarkMethods = new ArrayList<Method >();
    final Class benchClass = set.getClass();
    Method[] methods = benchClass.getDeclaredMethods();
    for (int i = 0; i < methods.length; i++){
        Annotation[] annotations = methods[i].getAnnotations();
        if (annotations.length != 0){
            for (int j = 0; j < annotations.length; j++)
            if (annotations[j].annotationType().toString().contentEquals("interface Benchmark"))
                benchmarkMethods.add(methods[i]);
        }
    }
    for (int i = 0; i < benchmarkMethods.size(); i++){
        String name = null;
        Method method = benchmarkMethods.listIterator().next();
        MeasureAndRecord(name, new IFunc() {
            @Override
            public Object onEvent() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
                return benchmarkMethods.get(i).invoke(set, null);
            }
        });
    }
    PrintWriter writer = new PrintWriter(System.out);
    PrintResults(writer);
}