Java 6 Source backward-compatibility and SQL

…衆ロ難τιáo~ 提交于 2019-11-30 02:24:10
notnoop

I got the following reply from a Sun Developer

The general evolution policy for APIs in the JDK for feature releases like JDK 7 is

  1. Don't break binary compatibility (as defined in JLSv3 chapter 13)
  2. Avoid introducing source incompatibilities
  3. Manage behavioral compatibility change

(For more, much more than you'd like to read on different kinds of compatibility see

"Kinds of Compatibility: Source, Binary, and Behavioral" and "Compatibly Evolving BigDecimal"

Adding methods to interfaces is binary compatible but source incompatible, so it is not commonly done. Generally, the more widely implemented an interface is, the less likely we are to add methods to it. The JDBC area is an exception to this policy and uses looser upgrade rules, but that does cause real issues when people want to upgrade to a new JDK release.

Note that adding new methods only break source compatibility, already compiled implementations of Statement or ResultSet in a JDBC driver will continue to run on a newer JDK. Only when you try to call a new method you will get a NoSuchMethodError.

They probably assume that database driver vendors that implement those methods are keeping up-to-date with new Java runtimes, and that it's better to introduce useful new methods and temporarily break compatibility.

Of course, they could've designed it better so that breaking compatibility wouldn't be necessary…

Sun never guarantees source compatibility between releases, only binary compatibility. The most common example is that source code that contains 'assert' or 'enum' identifiers will not compile under JDK 1.4 (for assert) or 1.5+ (for enum), but existing .class files will still run under those newer JVMs.

You can try using the -source flag to compile older .java files under newer JVMs but you may still run into problems if you're relying on jvm classes that have changed.

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