I have two classes and an interface (for example DatabaseModel
, LocalStore
, and InternalModelInterface). They're defined as follows;
public class DatabaseModel {
// ...
public static final String KEY_PARAM1 = "param1";
}
public class LocalStore implements InternalModelInterface {
// ...
public void function () {
String temp = InternalModelInterface.COLUMN_PARAM1;
}
}
public interface InternalModelInterface {
public static final String COLUMN_PARAM1 = DatabaseModel.KEY_PARAM1;
// ...
}
The issue I'm experiencing is that at runtime, when I call localStore.function()
, temp is being assigned null, as InternalModelInterface.COLUMN_PARAM1
is null. Does this make sense? Shouldn't InternalModelInterface.COLUMN_PARAM1
be evaluated at compile time and inlined?
This is for an Android application. Thanks in advance.
I'll further explain to clarify any confusion.
Objects of the DatabaseModel
class are instantiated as a JSON response is parsed. The constants defined in the DatabaseModel
class represent the keys to look for in the JSON response.
The InternalModelInterface
defines the column names used in the local (cache) database on the device. For several reasons (including they keys being illegal column names in SQLite), I'm not reusing the keys as column names.
The reason I'm using an interface and not just a plain class is that the interface also specifies required methods that need to be implemented by the third class, LocalStore.