0

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);

}
1
  • Meaning that your T type must be declared at compile time otherwise your DAO won't get generated. Commented May 11, 2019 at 4:48

1 Answer 1

1

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> { }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.