Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 620273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:44:43+00:00 2026-05-13T18:44:43+00:00

I am looking at some code where class level annotations are used to ‘add’

  • 0

I am looking at some code where class level annotations are used to ‘add’ properties to certain classes, later using reflection these properties are accessed and used.

My question:
When is it appropriate to use an annotation to add new fields to a class, instead of using an interface. What are some benefits and drawbacks to this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:44:43+00:00Added an answer on May 13, 2026 at 6:44 pm

    I don’t know that annotations would ever replace an interface, but I can kind of see the allure. It all depends on the implementations though.

    Annotations provide meta data to further describe code, which a consumer (most of the time) interprets at runtime using reflections. Using an interface, this contract of implementation is clearly defined.

    You could have:

    interface CrudDao<T> {
       Serializable create(T t);
       T read(Serializable id);
       void update(T t);
       void delete(T t);
    }
    

    This would be a cumbersome contract to implement, and would likely incur some sort of method chaining.

    Instead you could do something like:

    class SomeDao {
    
       @Create
       long create(SomeEntity e) { // code }
    
       @Read
       SomeEntity read(long id) { // code }
    
       @Update
       void update(SomeEntity e) { // code }
    
       @Delete
       void delete(SomeEntity e) { // code }
    }
    

    The drawback is that it would be cumbersome to use:

    class CrudFactory {
        long create(Class clazz, Object obj) {
           // loop through methods
           // find method with @Create
           // call method
        }    
    }
    

    Annotations in this example would be overkill a majority of the time, IMO. There is something to be said about a clearly defined, well documented contract.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 428k
  • Answers 428k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Why do your IDs need to be sequential? The App… May 15, 2026 at 1:14 pm
  • Editorial Team
    Editorial Team added an answer I believe you can do this @users = User.all @men… May 15, 2026 at 1:14 pm
  • Editorial Team
    Editorial Team added an answer (Assuming SQL Server - probably applies to most SQL implementations)… May 15, 2026 at 1:14 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.