I have an the following inheritance hierarchy: Staff (Abstract), HomeWorker (Abstract), Typist. Typist inherits from both abstract classes.
I am implementing an interface called Manager (for an academic assignment). The class that I am implementing Manager in is called Branch. One of the methods in Branch that I need to implement is setEmail, shown below.
The issue is that only Typists have email addresses, not other Staff (Translators and Clerks). All staff are stored in a TreeMap . I'm trying to check that the staff member specified by the id parameter is an instanceOf Typist, before I try calling the setEmail method (as this method only exists on Typist).
However, using BlueJ, as soon as I type instanceOf in the IF condition, the scope highlighting is telling me it's out of scope and that ')' is required after the staffMember reference.
Any ideas??
/** Sets email for a typist
* @param id represents the staff id
* @param email is the email address
*/
public void setEmail(String id, String email)
{
//Should be done in the typist class. This increases coupling though.
//Need to see if there is a way that I can do this using the staff class instead
Staff staffMember = staff.get (id);
//TO DO: Need to put an IF statement in that confirms the staff member is a typist, otherwise I could end up
//trying to set an email against a staff type which doesn't store email addresses
if (staffMember instanceOf Typist)
{
staffMember.setEmail(email);
}
}
Try using the keyword
instanceof
instead of
instanceOf
since this last one is not a keyword in Java.