You haven't placed any upper bound on T
, so the compiler doesn't know that it's an object that has a getId()
method.
You can create an interface:
interface HasId {
public int getId();
}
Then restrict T
to be a HasId
:
public abstract class GenericDatabaseManager<T extends HasId> {
And your Workout
, etc. classes can implement HasId
.
Then the compiler has enough information to know that whatever T
winds up being, it knows there is at least a getId()
method that can be called.