reinaldomoreira
reinaldomoreira

Reputation: 5908

Android Room's does not accept generic field type

I'm trying to have a base class which id field is of a generic type like

class BaseEntity<T>{
  private T id;
  //get, set;
}
class User extends BaseEntity<String> {
  //blah blah blah
}

and I have a DAO like this:

@Dao
public interface UserDao {

    @Query("SELECT * FROM user WHERE id = :id")
    Flowable<User> getUserById(String id);
}

and I get a compilation error:

app\build\generated\source\apt\irrisimples\debug\com\irrisimples\data\source\local\UserDao_Impl.java:275: error: cannot find symbol final T _tmpId; ^

and in UserDao_Impl:275:

final T _tmpId; _tmpId = _cursor.getString(_cursorIndexOfId);

So this means that Room couldn't figure out what was T and replace the value there. Is it a bug or am I doing something wrong?

P.S: Using Android Studio 3.1 BETA 3, and Room 1.0.0 (tested 1.1.0-alpha2)

Upvotes: 3

Views: 940

Answers (1)

reinaldomoreira
reinaldomoreira

Reputation: 5908

With reference to Google Issue Tracker

It should be fixed in 1.1.0-alpha3

Upvotes: 2

Related Questions