Problems

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:

  1. Inspecting packages: Write several examples for inspecting Java packages (for example, names, a list of classes, and so on).
  2. 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).
  3. Instantiating via a reflected constructor: Write a program that creates instances via reflection.
  1. Getting the annotation of a receiver type: Write a program that gets the annotation on a receiver type.
  2. Getting synthetic and bridge constructs: Write a program that gets synthetic and bridge constructs via reflection.
  3. Checking the variable number of arguments: Write a program that checks whether a method gets a variable number of arguments.
  4. Checking default methods: Write a program that checks whether a method is default.
  5. Nest-based access control via reflection: Write a program that provides access to nest-based constructs via reflection.
  6. 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.
  7. Reflecting annotations: Write several examples of fetching different kinds of annotations via reflection.
  8. Invoking an instance method: Write a program that invokes an instance method via reflection.
  9. Getting static methods: Write a program that groups the static methods of the given class and invokes one of them via reflection.
  10. 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.
  11. Getting public and private fields: Write a program that fetches the public and private fields of the given class via reflection.
  12. Working with arrays: Write several examples for working with arrays via reflection.
  13. Inspecting modules: Write several examples for inspecting Java 9 modules via reflection.
  14. Dynamic proxies: Write a program that relies on dynamic proxies for counting the number of invocations of the methods of the given interfaces.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset