A Subtle AutoCloseable Contract Change Between Java 7 and Java 8 | Java, SQL and jOOQ.
Java, SQL and jOOQ. Best Practices and Lessons Learned from Writing Awesome Java and SQL Code. Get some hands-on insight on what's behind developing jOOQ. A nice feature of the Java 7 type that was introduced to work with this statement is the fact that static code analysis tools can detect resource leaks. For instance, Eclipse: When you have the above configuration and you try running the following program, you'll get three warnings: public static void main(String[] args) throws Exception { Connection c = DriverManager.getConnection( "jdbc:h2:~/test", "sa", ""); Statement s = c.createStatement(); ResultSet r = s.executeQuery("SELECT 1 + 1"); r.next(); System.out.println(r.getInt(1)); } The output is, trivially c r . A quick fix (don't do this!) is to suppress the warning using an Eclipse-specific SuppressWarnings parameter: @SuppressWarnings("resource") public static void main(String[] args) throws Exception { ... } After all, WeKnowWhatWeReDoing™ and this is just a simple example,Read full article from A Subtle AutoCloseable Contract Change Between Java 7 and Java 8 | Java, SQL and jOOQ.
No comments:
Post a Comment