Am I right that's it impossible to use dynamic proxy with java enums?
Thanks in advance.
Am I right that's it impossible to use dynamic proxy with java enums?
Thanks in advance.
Dynamic proxies in Java can be created only for interfaces.
However, enum
s can implement interfaces, so that you can make your enum
implement an interface, and then create a dynamic proxy for that interface:
public interface A { ... }
public enum B implements A { ... }
A a = Proxy.newProxyInstance(cl, new Class[] { A.class }, ih);
That sounds right to me - just like you can't use dynamic proxies for static members.
Why do you need to do that in the first place? enums should generally be value objects or constants that don't need to be, or shouldn't be, proxied in the first place.