yyyyyyyyyyyyyyyyyyyy

博客园 首页 新随笔 联系 订阅 管理
    public class Tool {
        public void a()// /方法a 
        {
            System.out.print("tool.a()...");
        }
        public void b()// 方法b
        {
            System.out.print("tool.b()...");
        }
    }

    public class Control {
        public void invoke(int flag) {
            User user = new User();
            try {
                switch (flag) {
                case 0:
                    user.use(Tool.class.getMethod("a", null));
                    break;
                default:
                    user.use(Tool.class.getMethod("b", null));
                    break;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public class User {
        public void use(Method method) {
            Tool tool = new Tool();
            try {
                method.invoke(tool, null);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        public static void main(String[] args) {
            Control control = new Control();
            control.invoke(0);
        }
    }

 

posted on 2016-05-12 15:23  xxxxxxxx1x2xxxxxxx  阅读(211)  评论(0)    收藏  举报