import java.lang.reflect.Method;public class PrivateMethodReflectionExample {public static void main(String[] args) throws Exception {Class<?> targetClass = TargetClass.class;Method method = targetClass.getDeclaredMethod("handleOrderMsg", Message.class, Boolean.class);method.setAccessible(true);TargetClass instance = new TargetClass();Message message = new Message(); Boolean fromMq = true; Object result = method.invoke(instance, message, fromMq);if (result instanceof MessageResp) {MessageResp response = (MessageResp) result;} else {}}
}class TargetClass {private MessageResp handleOrderMsg(Message message, Boolean fromMq) {return new MessageResp(); }
}class Message {
}class MessageResp {
}