RoomDatabaseConstructor


public interface RoomDatabaseConstructor<T extends RoomDatabase>


Defines a class that can instantiate the Room generated implementation of an 'abstract' Database annotated RoomDatabase definition.

This interface is to be used in conjunction with 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:

expect object MusicDatabaseConstructor : RoomDatabaseConstructor<MusicDatabase>

one can reference the object's initialize during database creation:

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 definition via ConstructedBy.

Parameters
<T extends RoomDatabase>

The Database and ConstructedBy annotated class linked to this constructor.

See also
ConstructedBy

Summary

Public methods

abstract @NonNull T

Instantiates an implementation of T.

Public methods

initialize

Added in 2.7.0-alpha12
abstract @NonNullinitialize()

Instantiates an implementation of T.

Returns
@NonNull T

T - A new instance of T.