In this code :
public class MyClass {
private Object innerValue;
public Object getInnerValue() {
return this.innerValue;
}
public void setInnerValue(Object innerValue) {
this.innerValue = innerValue;
}
}
public class MyClassReadOnly extends MyClass {
MyClassReadOnly(MyClass cls) {
// Make a field by field copy
super.setInnerValue(cls.getInnerValue());
}
public void setInnerValue(Object innerValue) {
throw new UnsupportedOperationException(
"This is a read-only instance"
);
}
}
The compiler complains rightly about the unused parameter(never read) innerValue in MyClassReadOnly.setInnerValue().
I don't want to disable this kind of warnings since it's quite useful usually, and I don't want to have any warnings either to have a high signal/noise ratio.
I cannot use the @SuppressWarnings() construct as another question suggested since it's Java 1.4 only.
I thought about inserting dummy code like this, but it's not very satisfactory :
public void setInnerValue(Object innerValue) {
if (innerValue != null) { /* Do Nothing, but keep the compiler happy */ }
throw new UnsupportedOperationException("This is a read-only instance");
}