简体   繁体   中英

Getting Error while using Generic Dao in room with java

when I try to use Generic Dao in android Room I get this Erro :

Cannot use unbound generics in query methods. It must be bound to a type through base Dao class.

import android.arch.lifecycle.LiveData;
import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Delete;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.RawQuery;
import android.arch.persistence.room.Update;

import java.util.List;

@Dao
public interface BaseDaoAccess<T> {
    @Insert
    Long Insert(T entity);

    @Update
    void Update(T entity);
    @Delete
    void Delete(T entity);

    @RawQuery
    LiveData<List<T>> RowQuery(String query);

}

Due to type erasure , Java can't tell at runtime what T you mean. You can provide this information by creating a subtype that has the T bound to a specific type, such as this:

public interface CarDao extends BaseDaoAccess<Car> { }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM