开发者

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

开发者 https://www.devze.com 2023-04-11 07:22 出处:网络
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 see

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 wa开发者_如何学运维y to support both JDK6 and JDK7? Does simply implementing the new methods and never using them suffice?


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.


Instead of Eclipse, I would read the ResultSet javadoc.


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消