“Type of the parameter must be a class annotated with @Entity” while creating Generic DAO interface in Room

后端 未结 4 793
鱼传尺愫
鱼传尺愫 2020-12-16 19:52

I am using Room architecture component for persistence. I have created generic DAO interface to avoid boilerplate code. Room Pro Tips

But my code doesn\'t compile s

4条回答
  •  忘掉有多难
    2020-12-16 20:28

    The reason is that you specified ReasonDao type as generic parameter instead of Reason.

    Original code:

    @Dao
    public abstract class ReasonDao implements BaseDao {
    
       ...
    
    }
    

    Correct code:

    @Dao
    public abstract class ReasonDao implements BaseDao {
    
       ...
    
    }
    

    where Reason is the type marked with @Entity annotation.

    By the way, this is fixed in the accepted answer, but is not mentioned in the changelist :)

提交回复
热议问题