Given `Proxy.newProxyInstance(loader, new Class<?>[]{ PaymentGateway.class, AutoCloseable.class }, handler)`, describe precisely what gets built, when, and why the exact same mechanism means this call would fail outright if `PaymentGateway` were a concrete class instead of an interface — versus why a `final` class specifically breaks Spring's *other* proxying strategy in a completely different way.
Proxy.newProxyInstance doesn't fake anything or intercept calls through reflection tricks at call time — it generates an actual, real .class at run time that genuinely implements every interface it was handed (PaymentGateway and AutoCloseable both, here), with every method of both interfaces implemented to do exactly one thing: package up which method was called and with what arguments, and hand that off to the InvocationHandler. That generated class is cached per distinct interface set, so the generation cost is paid once, not on every proxy creation. It would fail outright for a concrete class because the mechanism can only generate a class that implements interfaces — Java has no multiple inheritance of implementation, so there's no way to generate a class that both implements PaymentGateway-as-a-class's behaviour and is a distinct object; Proxy is structurally an interface-only tool. final breaks the other mechanism (a generated subclass, via ByteBuddy/historically CGLIB) for a completely different, unrelated reason: that strategy works by generating a class that extends the target and overrides its methods, and Java forbids extending a final class at the language level — a different limitation, hit by a different proxying strategy, for a different structural reason.