Is there really `ResultSet.getObject(String, Class<T>) in JDK7?

无人久伴 提交于 2020-01-14 13:41:50

问题


I see quite a few changed interfaces in JDK7, e.g., the addition of ResultSet.getObject(String, Class<T>). I was greatly surprised by this incompatible change, especially because I've never seen it discussed.

I suppose the incompatibility doesn't matter when I use a JAR file instead of trying to compile the project myself, right?

What is the proper way to support both JDK6 and JDK7? Does simply implementing the new methods and never using them suffice?


回答1:


It seems

<T> T getObject(int columnIndex, Class<T> type) throws SQLException

and

<T> T getObject(String columnLabel,  Class<T> type) throws SQLException

were introduced in 1.7. (At least it says "Since 1.7") in the documentation. I agree, it's kind of a nasty change.

There are more changes in the java.sql interfaces. Connection for instance, got 5 new methods in 1.7. Hopefully the breaking changes are worthwhile.

Does simply implementing the new methods and never using them suffice?

Yes, but avoid using the @Overrides annotation on methods not present in the earlier version of the interface.




回答2:


Instead of Eclipse, I would read the ResultSet javadoc.




回答3:


You can pre-implement these methods, but you will not be able to use the @Override annotation. Looks like Java 7 doesn't define any new types which would prevent you from implementing the new methods in Java 6 but this is not always the case (e.g. usages of SavePoint in Java 1.4 but there are many others).



来源:https://stackoverflow.com/questions/7692320/is-there-really-resultset-getobjectstring-classt-in-jdk7

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