< prev index next >

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

Print this page




  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  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.security.AccessController;
  29 import java.security.PrivilegedAction;
  30 import java.util.Arrays;
  31 import java.util.Collections;
  32 import java.util.Deque;
  33 import java.util.HashMap;
  34 import java.util.HashSet;
  35 import java.util.IdentityHashMap;
  36 import java.util.LinkedList;
  37 import java.util.List;
  38 import java.util.Map;
  39 import java.util.Objects;
  40 import java.util.Set;
  41 import java.util.concurrent.atomic.AtomicInteger;
  42 import java.util.concurrent.atomic.AtomicLong;
  43 import java.util.stream.Collectors;
  44 import java.util.stream.Stream;
  45 
  46 import jdk.internal.loader.BootLoader;
  47 import jdk.internal.module.Modules;
  48 import jdk.internal.misc.Unsafe;
  49 import jdk.internal.misc.VM;
  50 import jdk.internal.reflect.CallerSensitive;
  51 import jdk.internal.reflect.Reflection;

  52 import sun.reflect.misc.ReflectUtil;
  53 import sun.security.action.GetPropertyAction;
  54 import sun.security.util.SecurityConstants;
  55 
  56 /**
  57  *
  58  * {@code Proxy} provides static methods for creating objects that act like instances
  59  * of interfaces but allow for customized method invocation.
  60  * To create a proxy instance for some interface {@code Foo}:
  61  * <pre>{@code
  62  *     InvocationHandler handler = new MyInvocationHandler(...);
  63  *     Foo f = (Foo) Proxy.newProxyInstance(Foo.class.getClassLoader(),
  64  *                                          new Class<?>[] { Foo.class },
  65  *                                          handler);
  66  * }</pre>
  67  *
  68  * <p>
  69  * A <em>proxy class</em> is a class created at runtime that implements a specified
  70  * list of interfaces, known as <em>proxy interfaces</em>. A <em>proxy instance</em>
  71  * is an instance of a proxy class.




  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  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.security.AccessController;
  29 import java.security.PrivilegedAction;
  30 import java.util.Arrays;
  31 import java.util.Collections;

  32 import java.util.HashMap;
  33 import java.util.HashSet;
  34 import java.util.IdentityHashMap;

  35 import java.util.List;
  36 import java.util.Map;
  37 import java.util.Objects;
  38 import java.util.Set;
  39 import java.util.concurrent.atomic.AtomicInteger;
  40 import java.util.concurrent.atomic.AtomicLong;
  41 import java.util.stream.Collectors;
  42 import java.util.stream.Stream;
  43 
  44 import jdk.internal.loader.BootLoader;
  45 import jdk.internal.module.Modules;
  46 import jdk.internal.misc.Unsafe;
  47 import jdk.internal.misc.VM;
  48 import jdk.internal.reflect.CallerSensitive;
  49 import jdk.internal.reflect.Reflection;
  50 import jdk.internal.util.concurrent.ClassLoaderValue;
  51 import sun.reflect.misc.ReflectUtil;
  52 import sun.security.action.GetPropertyAction;
  53 import sun.security.util.SecurityConstants;
  54 
  55 /**
  56  *
  57  * {@code Proxy} provides static methods for creating objects that act like instances
  58  * of interfaces but allow for customized method invocation.
  59  * To create a proxy instance for some interface {@code Foo}:
  60  * <pre>{@code
  61  *     InvocationHandler handler = new MyInvocationHandler(...);
  62  *     Foo f = (Foo) Proxy.newProxyInstance(Foo.class.getClassLoader(),
  63  *                                          new Class<?>[] { Foo.class },
  64  *                                          handler);
  65  * }</pre>
  66  *
  67  * <p>
  68  * A <em>proxy class</em> is a class created at runtime that implements a specified
  69  * list of interfaces, known as <em>proxy interfaces</em>. A <em>proxy instance</em>
  70  * is an instance of a proxy class.


< prev index next >