Interface ReflectiveHandle<T>
- Type Parameters:
T- The JVM type associated with this handle (e.g.Class,Field,Method, orConstructor)
- All Known Implementing Classes:
AggregateReflectiveHandle,ClassHandle,ConstructorMemberHandle,DynamicClassHandle,EnumMemberHandle,FieldMemberHandle,FlaggedNamedMemberHandle,MemberHandle,MethodMemberHandle,MinecraftClassHandle,NamedMemberHandle,ReflectedObjectHandle,StaticClassHandle,StaticReflectiveHandle,UnknownClassHandle
public interface ReflectiveHandle<T>
Represents an object that can be used for reflection operations.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault @NotNull ReflectiveHandle<T> cached()default @Nullable ReflectiveOperationExceptionDeprecated.I don't think there's going to be any practical use for this method.copy()Creates a new handle with the same properties.default booleanexists()@NotNull ReflectiveHandle<ReflectedObject> jvm()UsuallyReflectiveHandles returnMethodHandlewhen possible, however this method returns the raw object using the traditional Java reflection API which can be:FieldMethodConstructorClass (same as its normal ReflectiveHandle)reflect()The heart of the class.default TSame asreflect()except that it will return null if anyReflectiveOperationExceptionerrors occur.default TAn unchecked exception version ofreflect()(throws the original exception, not the aRuntimeException)default @NotNull ReflectiveHandle<T> unwrap()If this handle iscached(), then unwraps the real handle and returns it, otherwise it returns the same object.
-
Method Details
-
copy
Creates a new handle with the same properties. -
exists
@Contract(pure=true) default boolean exists()- Returns:
- true if this object exists at runtime, otherwise false.
-
catchError
Deprecated.I don't think there's going to be any practical use for this method.Catches anyReflectiveOperationExceptionthrown byreflect() -
unreflect
An unchecked exception version ofreflect()(throws the original exception, not the aRuntimeException)- Throws:
ReflectiveOperationException- throws silently.- See Also:
-
reflectOrNull
Same asreflect()except that it will return null if anyReflectiveOperationExceptionerrors occur.- See Also:
-
reflect
The heart of the class.- Returns:
- the final JVM object that exists in this runtime.
- Throws:
ReflectiveOperationException- if any errors occur while getting the object, including unknown objects, security issues, etc...- See Also:
-
jvm
UsuallyReflectiveHandles returnMethodHandlewhen possible, however this method returns the raw object using the traditional Java reflection API which can be:- Since:
- 14.0.0
- See Also:
-
cached
@NotNull @Experimental @Contract(value="-> new", pure=true) default @NotNull ReflectiveHandle<T> cached()AReflectiveHandlethat cachesreflect()andjvm(). Using this is not recommended. Please readXReflectionPerformance & Caching section for more information.Note that this cache is not immediate and instead, a
copy()of the handle is created which cannot be modified.This method should only be overridden for generic type adjustment.
- Since:
- 14.0.0
- See Also:
-
unwrap
If this handle iscached(), then unwraps the real handle and returns it, otherwise it returns the same object. This is useful when you want to access some properties of the handle.- Since:
- 14.0.0
- See Also:
-