我创建了一个名为GeneraFriendsTable
代码的通用类,如下所示:
public abstract class GeneralFriendsTable {
public static String TABLE_NAME;
public static final String COLUMN_ID = "_id";
public static final String COLUMN_NAME = "name";
public static void onCreate(SQLiteDatabase db) {
String DATABASE_CREATE = "CREATE TABLE " + TABLE_NAME + "(" +
COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
COLUMN_UNAME + " TEXT, " + ");";
db.execSQL(DATABASE_CREATE);
}
public static void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
}
}
我想从此类扩展时强制初始化字段TABLE_NAME
。
例如:
public class NewFriendsTable extends GeneralFriendsTable {
public static final String TABLE_NAME = "leaved_friends";
}
主要问题是:onCreate()
使用TABLE_NAME
扩展类
可以正常工作吗?