I have Model class like this
class ModelName {
public static void createTable(SQLiteDatabase db){
// code to create Table in DB
}
public static void deleteTable(SQLiteDatabase db){
// code to delete Table from DB
}
}
Every class has these static functions createTable, deleteTable
I’d like to iterate through classes like this:
SQLiteDatabase db_object = ....; //init the object
Class<?>[] models = {ModelName, OtherModelName};
for(Class<?> model : models){
model.deleteTable(db_object);
}
But defining Interface for public static void is not possible, and I have no reason to create Instances
How to achieve this?
Can’t really find the right words to describe my idea
I don’t know if this is what you are looking for but I just tested it with following.
Classes:
Main code:
Output:
Note: To me this looks like more overhead than just creating instances. Also, the code looks less readable and manageable like this.