Use the following problems to test your Java Reflection API programming prowess. I strongly encourage you to give each problem a try before you turn to the solutions and download the example programs:
- Inspecting packages: Write several examples for inspecting Java packages (for example, names, a list of classes, and so on).
- Inspecting classes and superclasses: Write several examples for inspecting classes and superclasses (for example, get Class via the class name, modifiers, implemented interfaces, constructors, methods, and fields).
- Instantiating via a reflected constructor: Write a program that creates instances via reflection.
- Getting the annotation of a receiver type: Write a program that gets the annotation on a receiver type.
- Getting synthetic and bridge constructs: Write a program that gets synthetic and bridge constructs via reflection.
- Checking the variable number of arguments: Write a program that checks whether a method gets a variable number of arguments.
- Checking default methods: Write a program that checks whether a method is default.
- Nest-based access control via reflection: Write a program that provides access to nest-based constructs via reflection.
- Reflection for getters and setters: Write several examples that invoke getters and setters via reflection. Additionally, write a program that generates getters and setters via reflection.
- Reflecting annotations: Write several examples of fetching different kinds of annotations via reflection.
- Invoking an instance method: Write a program that invokes an instance method via reflection.
- Getting static methods: Write a program that groups the static methods of the given class and invokes one of them via reflection.
- Getting generic types of methods, fields, and exceptions: Write a program that fetches the generic types of the given methods, fields, and exceptions via reflection.
- Getting public and private fields: Write a program that fetches the public and private fields of the given class via reflection.
- Working with arrays: Write several examples for working with arrays via reflection.
- Inspecting modules: Write several examples for inspecting Java 9 modules via reflection.
- Dynamic proxies: Write a program that relies on dynamic proxies for counting the number of invocations of the methods of the given interfaces.