Interface ReflectedObject
- All Superinterfaces:
AnnotatedElement
Represents a
Class, Constructor, Field or Method.
The main purpose of this class is to create an abstraction layer for common methods
such as the annotation methods (AnnotatedElement), getModifiers(), accessFlags(), name() and getDeclaringClass()
as well as a common class representing such types and grouping them together instead of a vague Object.
A proper instance can be created using the of() method.
The Object.toString() (with a prefix), Object.equals(Object) and Object.hashCode() are delegated
to the underlying unreflect() object.
- Since:
- 13.0.0
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptiondefault @NotNull @Unmodifiable Set<XAccessFlag> @Nullable Class<?> The class that defines this reflected object.intReturns the Java language modifiers for this class or interface, encoded in an integer.@NotNull Stringname()Gets the underlying JVM object which this class is a wrapper for.static @NotNull ReflectedObjectstatic @NotNull ReflectedObjectof(@NotNull Constructor<?> constructor) static @NotNull ReflectedObjectstatic @NotNull ReflectedObject@NotNull ReflectedObject.Typetype()@NotNull ObjectMethods inherited from interface java.lang.reflect.AnnotatedElement
getAnnotation, getAnnotations, getAnnotationsByType, getDeclaredAnnotation, getDeclaredAnnotations, getDeclaredAnnotationsByType, isAnnotationPresent
-
Method Details
-
of
@NotNull @Contract(value="_ -> new", pure=true) static @NotNull ReflectedObject of(@NotNull @NotNull Class<?> clazz) -
of
@NotNull @Contract(value="_ -> new", pure=true) static @NotNull ReflectedObject of(@NotNull @NotNull Constructor<?> constructor) -
of
@NotNull @Contract(value="_ -> new", pure=true) static @NotNull ReflectedObject of(@NotNull @NotNull Method method) -
of
@NotNull @Contract(value="_ -> new", pure=true) static @NotNull ReflectedObject of(@NotNull @NotNull Field field) -
unreflect
-
type
-
name
Gets the underlying JVM object which this class is a wrapper for. Mostly useful as a friendly and compact alternative toObject.toString(). -
getDeclaringClass
The class that defines this reflected object. This is obvious forConstructor,FieldandMethodobjects, but forClass.getDeclaringClass()it'd be enclosing class ornullif none.The subtilty with
Class.getDeclaringClass()is that anonymous inner classes are not counted as member of a class, whereas named inner classes are. Therefore, this method returns null for an anonymous class. The alternative methodClass.getEnclosingClass()works for both anonymous and named classes -
getModifiers
@Contract(pure=true) @MagicConstant(flagsFromClass=java.lang.reflect.Modifier.class) int getModifiers()Returns the Java language modifiers for this class or interface, encoded in an integer. The modifiers consist of the Java Virtual Machine's constants forpublic,protected,private,final,static,abstractandinterface; they should be decoded using the methods of classModifier.If the underlying class is an array class:
- its
public,privateandprotectedmodifiers are the same as those of its component type - its
abstractandfinalmodifiers are alwaystrue - its interface modifier is always
false, even when the component type is an interface
Classobject represents a primitive type or void, itspublic,abstract, andfinalmodifiers are alwaystrue. ForClassobjects representing void, primitive types, and arrays, the values of other modifiers arefalseother than as specified above.The modifier encodings are defined in section (JVM section 4.1) of The Java Virtual Machine Specification.
- Returns:
- the
intrepresenting the modifiers for this class - Since:
- Java 1.1
JLS 8.1.1 Class Modifiers
JLS 9.1.1. Interface Modifiers
JVM 4.1 The
ClassFileStructure - See Also:
- its
-
accessFlags
@NotNull @Contract(value="-> new", pure=true) default @NotNull @Unmodifiable Set<XAccessFlag> accessFlags()- Returns:
- An unmodifiable set of the access
flags for this class, possibly empty
If the underlying class is an array class:
- its
PUBLIC,PRIVATEandPROTECTEDaccess flags are the same as those of its component type - its
ABSTRACTandFINALflags are present - its
INTERFACEflag is absent, even when the component type is an interface
Classobject represents a primitive type or void, the flags arePUBLIC,ABSTRACT, andFINAL. ForClassobjects representing void, primitive types, and arrays, access flags are absent other than as specified above. - its
- Since:
- Java 20
- See Also:
-