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

  • SEARCH
  • Home
  • 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 7918929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:40:51+00:00 2026-06-03T15:40:51+00:00

I have this interface: public interface IDbTable extends Serializable { public int getId(); }

  • 0

I have this interface:

public interface IDbTable extends Serializable
{
    public int getId();
}

I need to obligate all the classes that implements IDbTable, to have an annotation “@DatabaseTable” and at least one field inside class that have “@DatabaseField”.
The only way of implementing IDbTable needs to be like this:

@DatabaseTable(tableName = "Something")
public static class TestTable implements IDbTable
{
            @DatabaseField
            public int id;

    public int getId()
    {
        return id;
    }
}

Is this possible with interface or inheritance?
Today i have an unit test that scan all the classes and check this requirements. Is this a good practice?

  • 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-06-03T15:40:52+00:00Added an answer on June 3, 2026 at 3:40 pm

    You can’t apply annotations to an interface that will be inherited by the implementing class, according to Java documentation: http://docs.oracle.com/javase/6/docs/api/java/lang/annotation/Inherited.html

    Indicates that an annotation type is automatically inherited. If an
    Inherited meta-annotation is present on an annotation type
    declaration, and the user queries the annotation type on a class
    declaration, and the class declaration has no annotation for this
    type, then the class’s superclass will automatically be queried for
    the annotation type. This process will be repeated until an annotation
    for this type is found, or the top of the class hierarchy (Object) is
    reached. If no superclass has an annotation for this type, then the
    query will indicate that the class in question has no such annotation.

    Note that this meta-annotation type has no effect if the annotated
    type is used to annotate anything other than a class. Note also that
    this meta-annotation only causes annotations to be inherited from
    superclasses; annotations on implemented interfaces have no effect.

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

Sidebar

Related Questions

I have a model that looks like this: public interface IEntity { int Id
Say I have this code - public interface ParentInterface1 { public List<? extends ChildInterface1>
If I have this classes: public interface IBinaryCalculator{ double addition(double numb1, double numb2); }
I have this simple interface/class: public abstract class Message {} public class Message1 extends
I have this interface public interface MyInterface{ Collection<T> Find(T t); Collection<T> FindAll(); T FindById(int
So lets say I have this interface: public interface IBox { public void setSize(int
I have this interface: public interface ISectionListItem { public int getLayoutId(); public void setProps(View
I have this interface public interface IDataPoint<T> extends Comparable<T> { public T getValue(); }
So I have this interface public interface EventHandler<E extends EventObject> { public void handleEvent(E
I have a method with this interface: public <A extends Message, B extends Message>

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.