📜  房间插入和返回 id - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:43.555000             🧑  作者: Mango

代码示例1
class StudentRepository private constructor(private val studentDao: StudentDao)
    {

        fun getStudents() = studentDao.getStudents()

        fun insertStudent(student: Student): Single? {
            return Single.fromCallable(
                Callable { studentDao.insertStudent(student) }
            )
        }

 companion object {

        // For Singleton instantiation
        @Volatile private var instance: StudentRepository? = null

        fun getInstance(studentDao: StudentDao) =
                instance ?: synchronized(this) {
                    instance ?: StudentRepository(studentDao).also { instance = it }
                }
    }
}