You have to tell Java that there is a setStartDate and a setEndDate method in the T objects.
interface Stuff {
void setStartDate(Calendar startDate);
void setEndDate(Calendar startDate);
}
public <T extends Stuff> void updateStuff(T stuffObject, Calendar startDate, Integer delta) {
stuffObject.setStartDate(startDate);
Calendar calendarEnd = Calendar.getInstance();
calendarEnd = startDate;
calendarEnd.add(Calendar.MONTH, delta);
stuffObject.setEndDate(calendarEnd);
}
Then your objects need to implement this interface.
class SomeStuff implements Stuff {
Calendar startDate;
Calendar endDate;
@Override
public void setStartDate(Calendar startDate) {
this.startDate = startDate;
}
@Override
public void setEndDate(Calendar startDate) {
this.endDate = endDate;
}
}
Incidentally, the way you are working out the end date is dangerous, you are actually modifying the Calendar you are passed as a parameter.
Calendar calendarEnd = Calendar.getInstance();
// Throw away the new Calendar and point calendarEnd at the parameter.
calendarEnd = startDate;
// change the parameter.
calendarEnd.add(Calendar.MONTH, delta);
See Defensive copy of Calendar for how to do this right. In particular this answer.