Mind Map
Class structure is unknown, analyze class at runtime.
Questions
Confused
Type//////TypeVariable////ParameterizedType
Reflection requires runtime permissions
Answered
Package/Class/Constructor/Method/Field/Modifier/Annotation/AnnotatedElement
Class
What is raw types, parameterized types, array types, type variables and primitive types?
Why and when reflection?
usage: junit4, spring
advantage: don’t need to know the class structure, access private members, analyze class at runtime
drawbacks: performance cost, security problems,
.class/getClass/Class.forName
getSuperclass()/getClasses()/getDeclaredClasses()/getDeclaringClass()/getEnclosingClass()/getPackage()/getModifiers()/getTypeParameters()/getGenericInterfaces()/getInterfaces()/getMethods() /getConstructors()/getFields()/getAnnotations()/
Constructor
getConstructor/getParameterTypes()/newInstance/
Method
getMethod()/getParameterTypes()/getReturnType()/getModifiers()/invoke/getDeclaredMethod()/setAccessible/
Field
getField()/getDeclaringClass()/getType()/get()/setInt()/setAccessible()
Annotation
Exception
NoSuchFieldException/SecurityException/IllegalAccessException
Reference
https://www.journaldev.com/1789/java-reflection-example-tutorial