I've read the Overriding and Hiding Methods tutorial. And from that, I gathered the following:
If a subclass defines a class method with the same signature as a class method in the superclass, the method in the subclass hides the one in the superclass.
As such, I did the following:
import javax.swing.JTextArea;
public final class JWrappedLabel extends JTextArea{
private static final long serialVersionUID = -844167470113830283L;
public JWrappedLabel(final String text){
super(text);
setOpaque(false);
setEditable(false);
setLineWrap(true);
setWrapStyleWord(true);
}
@Override
public void append(final String s){
throw new UnsupportedOperationException();
}
}
What I don't like about this design is that append
is still a visible method of the subclass. Instead of throwing the UnsupportedOperationException
, I could have left the body empty. But both feel ugly.
That being said, is there a better approach to hiding methods of the superclass?