反射执行指定的方法
public void reflectTest() throws Exception { Class clazz = Class.forName("com.jlpay.mng.agent.demo.AddAgent"); Method processMethod = clazz.getMethod("process", int.class); processMethod.invoke(clazz.newInstance(), 10); } public class AddAgent { public void process(int msg) { log.info("AddAgent process:" + msg); } }
判断两个类型是否一致
boolean isAssign = TypeUtils.isAssignable(String.class, Integer.class); log.info("isAssign: " + isAssign);
获取注解名
@Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited public @interface HandlerType { FlowableProcKeyEnum processType(); } Class clazz = Class.forName("com.jlpay.mng.agent.demo.AddAgent"); String type = clazz.getAnnotation(HandlerType.class).processType().value;
标签:反射,process,class,public,AddAgent,clazz,Class From: https://www.cnblogs.com/zhougongjin/p/17009017.html