If the constant interface anti-pattern is such a crime, why does Swing do it?

眉间皱痕 提交于 2019-12-05 04:24:55

The better solution of using static import was not available before java 5. Up to this point, abusing interfaces to import constants was considered acceptable because there was no better alternative. Once you have decided that JDialog implements WindowConstants (and asserted this in the docs), you cannot undo it without breaking backwards compatibility. Example:

JDialog d = new JDialog();
int flag = d.DISPOSE_ON_CLOSE;

While probably not good style, this is not so unusual and would break if we would change JDialog to use static imports instead of implementing WindowConstants.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!