我当前的Android应用程序使用Kotlin&Room
我有一个BaseDAO
界面,如下所示:-
interface BaseDAO<T> {
/**
* Insert an object in the database.
*
* @param obj the object to be inserted.
*/
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(obj: T) : Long
/**
* Insert multiple objects in the database.
*
* @param obj the objects to be inserted.
*/
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(obj: List<T>) : List<Long>
/**
* Update an object from the database.
*
* @param obj the object to be updated
*/
@Update
fun update(obj: T)
/**
* Delete an object from the database
*
* @param obj the object to be deleted
*/
@Delete
fun delete(obj: T)
}
我还希望有一个insert方法,可以在我的特定DAO接口中接受这样的DO的单个实例
@Dao
interface SingleDAO : BaseDAO<SingleDO> {
@Query("SELECT count(*) from single limit 1")
fun count(): Long
/**
* Insert single object in the database.
*
* @param obj the object to be inserted.
*/
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(obj: SingleDO) : Long
}
Android Studio报告此编译错误
'insert' hides member of supertype 'BaseDAO' and needs 'override' modifier
我想重载而不重载'insert'
方法
如果我尝试将'@JvmOverloads'
添加到我的重载insert
方法中,Android Studio会给我这个错误
`'@JvmOverloads'` annotation cannot be used on interface methods
如何重载我的BaseDAO方法?
答案 0 :(得分:1)
我相信您应该删除@JvmOverloads
批注:)