src/java.base/share/classes/java/lang/reflect/Proxy.java

Print this page




  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang.reflect;
  27 
  28 import java.lang.ref.WeakReference;
  29 import java.security.AccessController;
  30 import java.security.PrivilegedAction;
  31 import java.util.Arrays;
  32 import java.util.IdentityHashMap;
  33 import java.util.Map;
  34 import java.util.Objects;
  35 import java.util.concurrent.atomic.AtomicLong;
  36 import java.util.function.BiFunction;
  37 import sun.misc.ProxyGenerator;
  38 import sun.misc.VM;
  39 import sun.reflect.CallerSensitive;
  40 import sun.reflect.Reflection;
  41 import sun.reflect.misc.ReflectUtil;
  42 import sun.security.util.SecurityConstants;
  43 
  44 /**
  45  * {@code Proxy} provides static methods for creating dynamic proxy
  46  * classes and instances, and it is also the superclass of all
  47  * dynamic proxy classes created by those methods.
  48  *
  49  * <p>To create a proxy for some interface {@code Foo}:
  50  * <pre>
  51  *     InvocationHandler handler = new MyInvocationHandler(...);
  52  *     Class&lt;?&gt; proxyClass = Proxy.getProxyClass(Foo.class.getClassLoader(), Foo.class);
  53  *     Foo f = (Foo) proxyClass.getConstructor(InvocationHandler.class).
  54  *                     newInstance(handler);
  55  * </pre>
  56  * or more simply:
  57  * <pre>




  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang.reflect;
  27 
  28 import java.lang.ref.WeakReference;
  29 import java.security.AccessController;
  30 import java.security.PrivilegedAction;
  31 import java.util.Arrays;
  32 import java.util.IdentityHashMap;
  33 import java.util.Map;
  34 import java.util.Objects;
  35 import java.util.concurrent.atomic.AtomicLong;
  36 import java.util.function.BiFunction;
  37 import jdk.internal.reflect.ProxyGenerator;
  38 import sun.misc.VM;
  39 import sun.reflect.CallerSensitive;
  40 import sun.reflect.Reflection;
  41 import sun.reflect.misc.ReflectUtil;
  42 import sun.security.util.SecurityConstants;
  43 
  44 /**
  45  * {@code Proxy} provides static methods for creating dynamic proxy
  46  * classes and instances, and it is also the superclass of all
  47  * dynamic proxy classes created by those methods.
  48  *
  49  * <p>To create a proxy for some interface {@code Foo}:
  50  * <pre>
  51  *     InvocationHandler handler = new MyInvocationHandler(...);
  52  *     Class&lt;?&gt; proxyClass = Proxy.getProxyClass(Foo.class.getClassLoader(), Foo.class);
  53  *     Foo f = (Foo) proxyClass.getConstructor(InvocationHandler.class).
  54  *                     newInstance(handler);
  55  * </pre>
  56  * or more simply:
  57  * <pre>