Error While Using @Database annotation in Android

Hi all,

I am quite new to Kotlin and I am learning as I program an android App. I am using room persistence library in Android and while doing so I get the following error when I hover over entitties in @Database

Type mismatch
Required: Array<(KClass … KClass<*>)>
Found: () → KClass

Relevant code here:

@Database(entities = {Restaurants::class}, version = 1)
abstract class AppDatabase : RoomDatabase {

}

@Entity(tableName = “restaurants”)
class Restaurants {
@PrimaryKey(autoGenerate = true)
private val UID : Int = 0

}

Can someone please help me ? I read through the reflections document and I am still not able to understand this error properly.

Cheers … Nirmal

{Restaurants::class} is a lambda.

Try:

@Database(entities = arrayOf(Restaurants::class), version = 1)

or the newer way:

@Database(entities = [Restaurants::class], version = 1)

It works. Thank you @Eliote

Cheers … Nirmal

@Eliote Hi I do have a question though. What does “() → KClass<>” mean ?

Cheers … Nirmal

It’s a function that receives nothing () and returns a KClass<>.

https://kotlinlang.org/docs/reference/lambdas.html#function-types