setObject / getSpecificObject - when to type check?
From: VisionSet (spam_at_ntlworld.com)
Date: 10/29/04
- Next message: Alex Hunsley: "Re: java JFileChooser default name"
- Previous message: zcraven: "generating soccer fixtures from a list of teams"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 29 Oct 2004 15:04:12 GMT
In an inheritence structure of classes the superclass has:
Object record
public void setRecord(int i) {
record = model.getRecord(i)
}
this method is not overridden.
The subclasses have a package private getFlavouredRecord() method that
returns 'record' cast to its 'flavoured' type.
Should I override setRecord to ensure type is correct:
public void setRecord(int i) {
super.setRecord(i);
if(record != null && ! record instanceof Raspberry) {
throw new ClassCastException();
}
}
A bit bloaty for every subclass, but sensible?
Since setRecord() is public then perhaps I should, otherwise a bit OTT?
-- Mike W
- Next message: Alex Hunsley: "Re: java JFileChooser default name"
- Previous message: zcraven: "generating soccer fixtures from a list of teams"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|