How does Java use JDK’s dynamic proxy to implement multi-level proxy

  java, question

I know how to use dynamic proxy to realize the first-level proxy, but I don’t know how to realize the multi-level proxy, or can’t realize the multi-level proxy at all. Is similar tonew CarLogProxy(new CarTimeProxy(new Car())).move();Such multi-level agents.

Just in the process of learning dynamic agent, I also met this question. Without finding the answer, I groped my way to write it out. It can be realized, but it is not a scientific method. I don’t know yet. I hope Daniel will give me guidance.
The specific method or Handler will not be exposed, mainly the calling method. Because ..ChargeProxyHandlerAndLogProxyHandlerThey are all proxy classes, and the other methods are the same except to realize their respective businesses.

public class Test {
 public static void main(String[] args) {
 //instantiate the proxy class
 RailwayStation rs = new RailwayStation();
 Class<?  > c = rs.getClass();
 //Implement the charging transaction processor of the InvocationHandler and increase the charging processing
 InvocationHandler handler = new ChargeProxyHandler(rs);
 //Generate Proxy classes through proxy
 TicketBusiness t = (TicketBusiness) Proxy.newProxyInstance(c.getClassLoader(), c.getInterfaces(), handler);
 //Implements the log transaction processor of the InvocationHandler, adds log processing, and transfers the dynamically generated agent to the Handler
 InvocationHandler logHandler = new LogProxyHandler(t);
 TicketBusiness t2 = (TicketBusiness) Proxy.newProxyInstance(c.getClassLoader(), c.getInterfaces(), logHandler);

Running results:

Log = = > start selling tickets
 Serious ticket sales, price: 31 yuan
 Charged a handling fee, 5 yuan!
 Log = = > end ticket sales