setObject / getSpecificObject - when to type check?

V

VisionSet

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,244
Latest member
cryptotaxsoftware12

Latest Threads

Top