An open API service indexing awesome lists of open source software.

https://github.com/asrieldreemurrgm/java_reflections_and_annotations

Study project focused on runtime reflections and custom annotations, showcasing how attributes can be used to interact with objects dynamically.
https://github.com/asrieldreemurrgm/java_reflections_and_annotations

annotations exceptions java oop reflections spring-tool-suite4

Last synced: about 1 year ago
JSON representation

Study project focused on runtime reflections and custom annotations, showcasing how attributes can be used to interact with objects dynamically.

Awesome Lists containing this project

README

          

Study_Of_Reflections



About

Study project focused on Java Reflections and Custom Annotations, demonstrating how to interact with objects and metadata dynamically at runtime.

It includes examples involving class analysis, constructor usage, field access, and annotation-based behavior replacement.


📌 Features



  • Created and used a custom annotation KeyType to identify entity keys (e.g., CPF or Product Code);

  • Used reflections to get class names, constructors, and method return types at runtime;

  • Dynamic instantiation and data printing using reflection API;

  • Handled exceptions when fetching annotation values with detailed Javadocs;

  • Project based on and adapted from a Java CRUD example I previously developed.


🗂️ Project Structure




  • br.com.eaugusto.reflection: Contains reflection logic and main application AppReflections;


  • br.com.eaugusto.model: Holds the Product class with fields like code, description, and price;


  • br.com.eaugusto.annotations: Contains the KeyType annotation and related handling logic.


🚀 How to Run



  1. Clone the repository and open it in your IDE (STS, Eclipse, IntelliJ);

  2. Run AppReflections.java to see class and field reflection in action;

  3. Explore KeyType and see how it replaces logic from previous interfaces.

  4. Additionally, run App.java and see the CRUD in action.


📅 Commit Highlights


June 11, 2025



  • Added exception handling in getKey() and documented it with Javadoc;

  • Created and applied KeyType annotation to entities (replacing getCodeOrCPF());

  • Removed unnecessary storage logic to simplify the study focus;

  • Copied base CRUD from a previous repository for annotation integration.


June 10, 2025



  • Implemented logic to return method names and their types using reflection;

  • Suppressed non-critical warnings specific to study context.


June 9, 2025



  • Created main class AppReflections using Java Reflection to get class details, instantiate objects and print data;

  • Created the Product class with fields: code, description, and price.


📚 Learning Goals



  • Understand the use of Java Reflection to inspect and manipulate class structure at runtime;

  • Learn how to create and apply custom annotations for metadata-driven logic;

  • Replace interface logic with annotations for more flexible code design.