force subclasses to include constant in abstract java class
This will not work that way. I would define these as abstract functions:
protected abstract String objectName();
protected abstract String objectDef();
And in the subclass:
private static final String OBJECT_NAME = "awesome class";
private static final String OBJECT_DEF = "bla";
protected String objectName(){
return OBJECT_NAME;
}
protected String objectDef(){
return OBJECT_DEF;
}
The methods are not static
, but I think this is the closest you can get to what you want.
You can force sub-class to define a method which can be a constant for that class.
protected abstract String objectName();
protected abstract String objectDef();
Note: if you have sub-class of your sub-classes, these might "forget" to override these methods.