jdk 中的代理
java.lang.reflect.Proxy 代理:语义就是,让某个事物代表另外一个事物。 实现的功能:让不方便出现的事物,有另外的事物进行处理。 对于Java来说,我个人的理解就是:需要类A来代表类B,类B的方法在类A中有实现,且类A不继承自类B。 为了理解,如下类A均是代理类B 那么Java中的源码是如何实现的呢? -------note:查看源码和设计是个相反的过程,需要通过如何使用来看这个源码的实现。 获得代理类的方法由如下该类实现。 java.lang.reflect.Proxy.newProxyInstance(ClassLoader classLoader, Class<?>[] interfaces, InvocationHandler h); Parameters: loader - the class loader to define the proxy class interfaces - the list of interfaces for the proxy class to implement h - the invocation handler to dispatch method invocations to 源码部分查看 该方法返回结果。 return cons .newInstance(new Object[]{h}); 源码部分