Instance

public final class Instance

Instance represents an object instance. It wraps the actual object instance and provides methods for invoking the object’s methods.

Author:Hugo Y. K. Lam

Constructors

Instance

public Instance(Object source)

Creates a new instance of Instance.

Parameters:
  • source – an object instance, its class, or its class name.
Throws:
  • InstanceException – if errors occurred in the creation of the instance.

Instance

public Instance(Object source, ClassLoader loader)

Creates a new instance of Instance.

Parameters:
  • source – an object instance, its class, or its class name.
  • loader – the class loader for loading the instance’s class.
Throws:
  • InstanceException – if errors occurred in the creation of the instance.

Instance

public Instance(Object source, Class[] initargTypes, Object[] initargs)

Creates a new instance of Instance.

Parameters:
  • source – an object instance, its class, or its class name.
  • initargTypes – the constructor’s parameter types.
  • initargs – the constructor’s parameters.
Throws:
  • InstanceException – if errors occurred in the creation of the instance.

Instance

public Instance(Object source, ClassLoader loader, Class[] initargTypes, Object[] initargs)

Creates a new instance of Instance.

Parameters:
  • source – an object instance, its class, or its class name.
  • loader – the class loader for loading the instance’s class.
  • initargTypes – the constructor’s parameter types.
  • initargs – the constructor’s parameters.
Throws:
  • InstanceException – if errors occurred in the creation of the instance.

Methods

getObject

public Object getObject()

Gets the object this instance represents.

Returns:the object this instance represents.

invoke

public Object invoke(String methodName)

Invokes a method in the object that this instance represents.

Parameters:
  • methodName – the method name.
Throws:
  • InstanceException – if the method could not be invoked.
  • InvocationTargetException – if the invoked method has thrown an exception.
Returns:

the object returned by the invoked method.

invoke

public Object invoke(String methodName, Object[] parameters)

Invokes a method in the object that this instance represents.

Parameters:
  • methodName – the method name.
  • parameters – the parameters.
Throws:
  • InstanceException – if the method could not be invoked.
  • InvocationTargetException – if the invoked method has thrown an exception.
Returns:

the object returned by the invoked method.

invoke

public Object invoke(String methodName, Object[] pt, Object[] parameters)

Invokes a method in the object that this instance represents.

Parameters:
  • methodName – the method name.
  • pt – the parameter types.
  • parameters – the parameters.
Throws:
  • InstanceException – if the method could not be invoked.
  • InvocationTargetException – if the invoked method has thrown an exception.
Returns:

the object returned by the invoked method.

isMethodExist

public boolean isMethodExist(String name, Object[] pt)

Check if the specified method exists.

Parameters:
  • name – the method name.
  • pt – the parameter types.
Returns:

true if the specified method exists.