Can I not have non-abstract methods in my DAO interface?
I have a DAO function that takes an object, but since you can’t destructure the object directly, I manually unwrap it and call a private method:
Copy code
data class Foo(val x: Int, val y: String)
@Dao interface MyDao {
@Query("...")
private suspend fun _getData(x: Int, y: String): Int
suspend fun getData(foo: Foo) = _getData(foo.x, foo.y)
}
But I get an error when trying to build my project:
Copy code
error: MyDao_Impl is not abstract and does not override abstract method getData(......
How do I resolve this without forcing a non-DAO function to do the unwrapping?
kyleg
01/26/2020, 10:18 PM
OK, looks like the answer is the pull that non-abstract method out and make it an extension function:
Copy code
@Dao interface MyDao {
@Query("..")
suspend fun getData(x: Int, y: String): Int
}
suspend fun MyDao.getData(foo: Foo) =
getData(foo.x, foo.y)