SWT中的许多组件是不允许被继承的,例如Button。这遵循Josh Bloch的建议:design for inheritance or prohibit it。
如果需要直接继承,且在构造方法中用如下语句:
super(parent, style);
则会引发错误:org.eclipse.swt.SWTException: Subclassing not allowed。
如果一定要继承,则可以在子类中加入方法:
protected void checkSubclass(){
}
然后在构造方法中调用该方法如下:
super(parent, style);
checkSubclass();