Reputation: 20906
public class DbManager<T extends Dao> {
public DbManager(Context c) {
setCreateDatabaseScript(T);
}
public void setCreateDatabaseScript(T dao) {
this.createDatabaseScript = ((Dao)dao).createTable();
}
//..
}
how can I inside constructor call setCreateDatabaseScript. I try like in example but not working. What is correct syntax?
Upvotes: 0
Views: 73
Reputation: 58
The object, T, has never been declared or instantiated when it is used in your constructor.
Upvotes: 0
Reputation: 124215
setCreateDatabaseScript(T dao)
needs instance of T
so you probably should pass it in constructor
public DbManager(Context c, T dao) {
setCreateDatabaseScript(dao);
}
Also since T extends Dao
you don't need to cast it to Dao, just use dao.createTable();
Upvotes: 1
Reputation: 15523
public DbManager(Context c) {
setCreateDatabaseScript(T);
}
You have to call setCreateDatabaseScript with an object of type T as parameter, not just with T.
Upvotes: 0