# RoomDatabaseConstructor

# RoomDatabaseConstructor

Artifact:[androidx.room:room-runtime](https://developer.android.com/jetpack/androidx/releases/room)  
[View Source](https://cs.android.com/search?q=file:androidx/room/RoomDatabaseConstructor.kt+class:androidx.room.RoomDatabaseConstructor)  
Added in[2.7.0](https://developer.android.com/jetpack/androidx/releases/room#2.7.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/room/RoomDatabaseConstructor "View this page in Java")
Common/AllAndroid/JVMNative/C/iOSJavaScript
  - Cmn  

  ```
  interface RoomDatabaseConstructor<T : RoomDatabase>
  ```

*** ** * ** ***

Defines a class that can instantiate the Room generated implementation of an 'abstract'[Database](https://developer.android.com/reference/kotlin/androidx/room/Database)annotated[RoomDatabase](https://developer.android.com/reference/kotlin/androidx/room/RoomDatabase)definition.

This interface is to be used in conjunction with[ConstructedBy](https://developer.android.com/reference/kotlin/androidx/room/ConstructedBy)to define an 'expect' declaration of an 'object' that implements this interface. The defined 'object' can then be optionally used in Room's`databaseBuilder`or`inMemoryDatabaseBuilder`as the`factory`.

For example, with the following object definition:  

```kotlin
expect object MusicDatabaseConstructor : RoomDatabaseConstructor<MusicDatabase>
```

one can reference the object's[initialize](https://developer.android.com/reference/kotlin/androidx/room/RoomDatabaseConstructor#initialize())during database creation:  

```kotlin
fun createDatabase(): MusicDatabase {
    return Room.inMemoryDatabaseBuilder<MusicDatabase>(
        factory = MusicDatabaseConstructor::initialize
    ).build()
}
```

For Room to correctly and automatically use 'actual' implementations of this interface, they must be linked to their respective[Database](https://developer.android.com/reference/kotlin/androidx/room/Database)definition via[ConstructedBy](https://developer.android.com/reference/kotlin/androidx/room/ConstructedBy).  

|                                             Parameters                                              |
|-----------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `<T : `[RoomDatabase](https://developer.android.com/reference/kotlin/androidx/room/RoomDatabase)`>` | The[Database](https://developer.android.com/reference/kotlin/androidx/room/Database)and[ConstructedBy](https://developer.android.com/reference/kotlin/androidx/room/ConstructedBy)annotated class linked to this constructor. |

|                                          See also                                           |
|---------------------------------------------------------------------------------------------|---|
| [ConstructedBy](https://developer.android.com/reference/kotlin/androidx/room/ConstructedBy) |   |

## Summary

| ### Public functions |
|----------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----|
| `T`                  | [initialize](https://developer.android.com/reference/kotlin/androidx/room/RoomDatabaseConstructor#initialize())`()` Instantiates an implementation of[T](https://developer.android.com/reference/kotlin/androidx/room/RoomDatabaseConstructor). | Cmn |

## Public functions

### initialize

Cmn  
Added in[2.7.0](https://developer.android.com/jetpack/androidx/releases/room#2.7.0)  

```
fun initialize(): T
```

Instantiates an implementation of[T](https://developer.android.com/reference/kotlin/androidx/room/RoomDatabaseConstructor).  

| Returns |
|---------|-----------------------------------------------------------------------------------------------------------------|
| `T`     | T - A new instance of[T](https://developer.android.com/reference/kotlin/androidx/room/RoomDatabaseConstructor). |