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?
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