Sorry for not specific title, I don't really know how to name it better.
I have the following example:
class User
interface Repository<T, ID>
interface UserRepository : Repository<User, Long>
abstract class RepositoryTest<T, ID> {
abstract var repository: Repository<T, ID>
}
class UserRepositoryTest : RepositoryTest<User, Long>() {
//Error: Var-property type is "UserRepository", which is not a type of overriden
lateinit override var repository: UserRepository
}
I need this architecture for the database testing. Repository
have methods like insert, save, delete etc. I want to use this abstraction in RepositoryTest
to delete all entries and insert needed data before each test. In UserRepositoryTest
I want to specify the repository as UserRepository
(it's a child of Repository
), but I take an error mentioned in the example.
Why it gives me the error? I thought I can pass a subtype`s type.
repository
is a var
field. Since UserRepositoryTest
can be referred as RepositoryTest<User, Long>
, you should be able to assign Repository<User, Long>
to the repository
field. However, it does not have to be a UserRepository
, hence the error.
Changing repository
to val
in RepositoryTest
class should fix it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With