Skip to content

Most visited

Recently visited

navigation
Added in API level 1

Proxy

public class Proxy
extends Object implements Serializable

java.lang.Object
   ↳ java.lang.reflect.Proxy


Proxy defines methods for creating dynamic proxy classes and instances. A proxy class implements a declared set of interfaces and delegates method invocations to an InvocationHandler.

See also:

Summary

Fields

protected InvocationHandler h

The invocation handler on which the method calls are dispatched.

Protected constructors

Proxy(InvocationHandler h)

Constructs a new Proxy instance with the specified invocation handler.

Public methods

static InvocationHandler getInvocationHandler(Object proxy)

Returns the invocation handler of the specified proxy instance.

static Class<?> getProxyClass(ClassLoader loader, Class...<?> interfaces)

Returns the dynamically built Class for the specified interfaces.

static boolean isProxyClass(Class<?> cl)

Indicates whether or not the specified class is a dynamically generated proxy class.

static Object newProxyInstance(ClassLoader loader, Class[]<?> interfaces, InvocationHandler invocationHandler)

Returns an instance of the dynamically built class for the specified interfaces.

Inherited methods

From class java.lang.Object

Fields

h

Added in API level 1
InvocationHandler h

The invocation handler on which the method calls are dispatched.

Protected constructors

Proxy

Added in API level 1
Proxy (InvocationHandler h)

Constructs a new Proxy instance with the specified invocation handler.

Parameters
h InvocationHandler: the invocation handler for the newly created proxy

Public methods

getInvocationHandler

Added in API level 1
InvocationHandler getInvocationHandler (Object proxy)

Returns the invocation handler of the specified proxy instance.

Parameters
proxy Object: the proxy instance
Returns
InvocationHandler the invocation handler of the specified proxy instance
Throws
IllegalArgumentException if the supplied proxy is not a proxy object

getProxyClass

Added in API level 1
Class<?> getProxyClass (ClassLoader loader, 
                Class...<?> interfaces)

Returns the dynamically built Class for the specified interfaces. Creates a new Class when necessary. The order of the interfaces is relevant. Invocations of this method with the same interfaces but different order result in different generated classes. The interfaces must be visible from the supplied class loader; no duplicates are permitted. All non-public interfaces must be defined in the same package.

Parameters
loader ClassLoader: the class loader that will define the proxy class
interfaces Class: an array of Class objects, each one identifying an interface that will be implemented by the returned proxy class
Returns
Class<?> a proxy class that implements all of the interfaces referred to in the contents of interfaces
Throws
IllegalArgumentException if any of the interface restrictions are violated
NullPointerException if either interfaces or any of its elements are null

isProxyClass

Added in API level 1
boolean isProxyClass (Class<?> cl)

Indicates whether or not the specified class is a dynamically generated proxy class.

Parameters
cl Class: the class
Returns
boolean true if the class is a proxy class, false otherwise
Throws
NullPointerException if the class is null

newProxyInstance

Added in API level 1
Object newProxyInstance (ClassLoader loader, 
                Class[]<?> interfaces, 
                InvocationHandler invocationHandler)

Returns an instance of the dynamically built class for the specified interfaces. Method invocations on the returned instance are forwarded to the specified invocation handler. The interfaces must be visible from the supplied class loader; no duplicates are permitted. All non-public interfaces must be defined in the same package.

Parameters
loader ClassLoader: the class loader that will define the proxy class
interfaces Class: an array of Class objects, each one identifying an interface that will be implemented by the returned proxy object
invocationHandler InvocationHandler: the invocation handler that handles the dispatched method invocations
Returns
Object a new proxy object that delegates to the handler h
Throws
IllegalArgumentException if any of the interface restrictions are violated
NullPointerException if the interfaces or any of its elements are null
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.