I am adapting the Android Room with a View tutoria...
# android
e
I am adapting the Android Room with a View tutorial to my domain. As shown in the picture, I get an
Unresolved reference: Callback
error in the expression
ContactDatabase.Callback
. Why? As shown,
ContactDatabase
extends
RoomDatabase
, and
RoomDatabase.Callback
is defined.
Copy code
@Database(entities = arrayOf(ContactEntity::class), version = 1)
abstract class ContactDatabase : RoomDatabase() {
    abstract fun contactDao(): ContactDao
    lateinit var callback: RoomDatabase.Callback

    private class ContactDatabaseCallback(
        private val scope: CoroutineScope
    ) : ContactDatabase.Callback() {  <-- Error on this line
t
I think you meant:
Copy code
abstract class ContactDatabase : RoomDatabase() {
  [...]

  private class ContactDatabaseCallback(
    private val scope: CoroutineScope
  ) : RoomDatabase.Callback() { <-- Difference is here
  }
}
🥇 1
e
I discovered that removing the outer class name from the line with the error eliminates the error:
Copy code
@Database(entities = arrayOf(ContactEntity::class), version = 1)
abstract class ContactDatabase : RoomDatabase() {
    abstract fun contactDao(): ContactDao
    lateinit var callback: RoomDatabase.Callback
    private class ContactDatabaseCallback(
        private val scope: CoroutineScope
    ) : Callback() { <-- No error here
How come?
Thank you, @tseisel. That was it.
t
For your 2nd question, because
ContactDatabase
extends from
RoomDatabase
, it can access its inner class
RoomDatabase.Callback
without specifying the full qualifier. That's a rather odd rule, probably inherited from Java.
e
@tseisel Why doesn’t
ContactDatabase.Callback
exist, when
ContactDatabase
extends
RoomDatabase
?
t
Inner classes definitions are not inherited. You have to define yours in `ContactDatabase
âś… 1
e
Thank you!