public abstract class DynamicRewriter<C> extends Object
rewrite(java.lang.Class<R>, C, boolean)
method with a method B rewrite(A x)
to match
objects of class A
, and replace them by objects of
class B
. Methods of subclasses will only be considered
as matches for an input if they have public
access to be retrieved with Class.getMethod(java.lang.String, java.lang.Class<?>...)
rewrite
, and C
. Constructor and Description |
---|
DynamicRewriter() |
Modifier and Type | Method and Description |
---|---|
<R> R |
rewrite(Class<R> targetClass,
C x,
boolean total)
Finds the best-matching
rewrite method for the
dynamic type of a given object and invokes it. |
public <R> R rewrite(Class<R> targetClass, C x, boolean total)
rewrite
method for the
dynamic type of a given object and invokes it.targetClass
- the expected class of the result.x
- the input object.total
- if true
and x
is
null
or no match is found, then x
is
cast to the class targetClass
and returned.IllegalArgumentException
- if the matching method throws an
exception or cannot be invoked for some reason, or if
total
is false
and no match is found.ClassCastException
- if the result cannot be cast to the
class targetClass
.NullPointerException
- if total
is false and
x
is null
.see also the complete user documentation .