【发布时间】:2020-03-28 23:23:39
【问题描述】:
我可以编译代码:
@Update
public abstract int update(Iterable<T> objects);
但是当我尝试编译时
@Insert(onConflict = OnConflictStrategy.IGNORE)
public abstract List<Long> insert(Iterable<T> objects);
编译器有一条消息:
error: no suitable method found for insertAndReturnIdsList(Iterable<SessionKey>)
method EntityInsertionAdapter.insertAndReturnIdsList(SessionKey[]) is not applicable
(argument mismatch; Iterable<SessionKey> cannot be converted to SessionKey[])
method EntityInsertionAdapter.insertAndReturnIdsList(Collection<? extends SessionKey>) is not applicable
(argument mismatch; Iterable<SessionKey> cannot be converted to Collection<? extends SessionKey>)
我发现androidx.room.EntityInsertionAdapter需要Collection作为参数:
List<Long> insertAndReturnIdsList(Collection<? extends T> entities)
而不是Iterable。 为什么?
【问题讨论】:
-
您是否尝试过使插入方法无效?原因 List
显示错误。 -
是的,
void insert(Iterable<T> objects)不会在编译时产生错误,但是为什么update和insert方法的接口会有这样的差异!?
标签: android collections insert android-room iterable