When you implement Serializable for your class, IDE shows a warning that The serializable class YOURCLASS does not declare a static final serialVersionUID field of type long.
How can I define an interface that forces the IDE to show this warning for my field?
public class MyClass implements Serializable
{
// this class has warning
}
public class MyClass implements MyInterface
{
// I want to have warning for this class
}
public interface MyInterface{
public static final long myField;
}
You can use aspectj to generate compiler warnings or errors. It is sometimes used to enforce architectural aspects, but might be applicable for you, too.
The Pointcut definitions itself are left as an excercise for the reader :-)
@Aspect
public class ArchitecturalEnforcement {
@Pointcut("...")
public void implementsInterface() {}
@Pointcut("...")
public void definesConstant(){}
/** Advice that defines an error when a GUI method calls a method in the DAO layer */
@DeclareWarning("implementsInterface() && !definesConstant()")
private static final String WARNING= "...";
}
Read more on AOP (Aspect Oriented Programming)