为什么 java.sql.Statement 会破坏向后兼容性?
从 1.6 版本开始,Statement
接口中又声明了三个方法。
据我了解,这打破了java最大的优势之一——向后兼容性。我的项目从 jdk 1.5 过渡到 jdk 1.6 后不再编译,我必须更改代码。
以如此糟糕的方式添加这三个方法(isPoolable
、setPoolable
、isClosed
)的原因是什么?
There are three more methods declared in Statement
interface since version 1.6.
As I understand, this breaks one of the biggest java advantages - backward compatibility. My project just not compiled any more after transition from jdk 1.5 to jdk 1.6 and I have to change the code.
What is the reasoning of adding these three methods (isPoolable
, setPoolable
, isClosed
) in such a bad way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您实现接口(例如,您正在编写自己的 JDBC 驱动程序),则添加的接口方法就会出现问题。如果您有一个使用这些方法的库调用一个未实现这些方法的库,您将收到 NoSuchMethodError。
我认为添加这些方法是因为对于大多数用例来说,它被认为是无害的。
Added interface methods are a problem if you implement the interface e.g. you are writing your own JDBC driver. If you have a library which uses these method calling a library which doesn't implement these methods you will get a NoSuchMethodError.
I assume these methods were added because for most use cases its considered harmless.