Interface ReflectiveProxyObject
@Experimental
public interface ReflectiveProxyObject
All interfaces used for
XReflection.proxify(Class) must
extend this interface. Instances of this class can be thought as a dynamic Class object that
contains methods, fields and constructors, whether final or static, but all in forms of public methods.
The first instance of this class should be used for only calling constructors, static methods and fields,
and bindTo(Object) method. However, it's possible to create two separate classes for constructors
and static members and one for non-static members without constructors.
- Since:
- 13.0.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescription@NotNull ReflectiveProxyObjectReturns a newReflectiveProxyObjectthat's linked to a newReflectiveProxywith the given instance.@NotNull Class<?> Get the real class object that this proxy object is referencing.@NotNull Objectinstance()Gets the instance that the methods are delegating to.default @org.jetbrains.annotations.NotNull booleanisInstance(@Nullable Object object) Equivalent to the code:default @NotNull Object[]newArray(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int length) Equivalent to the code:default @NotNull Object[]newArray(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int... dimensions) Equivalent to the code:
-
Method Details
-
instance
Gets the instance that the methods are delegating to. Throw an exception if used on the factory object. -
getTargetClass
Get the real class object that this proxy object is referencing.- Since:
- 14.0.0
-
isInstance
@NotNull @NonExtendable @Contract(pure=true) default @org.jetbrains.annotations.NotNull boolean isInstance(@Nullable @Nullable Object object) Equivalent to the code:
This results in more performance in generated code instead of doing:object instanceof TargetClass
So do note that this will never return true if you pass agetTargetClass().isInstance(object.getClass())ReflectiveProxyObjectto it.- Since:
- 14.0.0
-
newArray
@NotNull @NonExtendable @Contract(pure=true) default @NotNull Object[] newArray(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int length) Equivalent to the code:
This results in a slight performance improvement in generated code instead of doing:new TargetClass[length]
So do note that this will never return true if you pass aArray.newInstance(getTargetClass(), length)ReflectiveProxyObjectto it.- Since:
- 14.1.0
-
newArray
@NotNull @NonExtendable @Contract(pure=true) default @NotNull Object[] newArray(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int... dimensions) Equivalent to the code:
This results in a slight performance improvement in generated code instead of doing:new TargetClass[length0][length1][...]
So do note that this will never return true if you pass aArray.newInstance(getTargetClass(), length)ReflectiveProxyObjectto it.- Since:
- 14.1.0
-
bindTo
@NotNull @OverrideOnly @Contract(value="_ -> new", pure=true) @NotNull ReflectiveProxyObject bindTo(@NotNull @NotNull Object instance) Returns a newReflectiveProxyObjectthat's linked to a newReflectiveProxywith the given instance.- Parameters:
instance- the instance to bind.
-