要使用Room,我们创建一个扩展create-react-app
的抽象类,并使用构建器来获取它的实例。
RoomDatabase
我知道Room为该类生成实现,但是如果声明为@Database(entities = {Note.class}, version = 1)
public abstract class NoteDatabase extends RoomDatabase {
private static NoteDatabase instance;
public abstract NoteDao noteDao();
public static synchronized NoteDatabase getInstance(Context context) {
if (instance == null) {
instance = Room.databaseBuilder(context.getApplicationContext(),
NoteDatabase.class, "note_database")
.fallbackToDestructiveMigration()
.addCallback(roomCallback)
.build();
}
return instance;
}
的实例是抽象的,怎么可能得到呢?它不应该使用其他名称吗?