If you have been keeping up with the latest JDK 1.7 release notes then you are aware that JDK 1.7 will not work with any current version (that I have tested) of Eclipse or Netbeans (have not tested Intelli-J). This is due to the new additions of the functional programming features: closures being the most notable one that blows up for me a lot of the times.
I do see there is a new September binary snapshot out there on [JDK 7 latest releases]: [02_SEP_2010 Release]
Netbeans JDK7 Beta Site [http://wiki.netbeans.org/Java_EditorJDK7]
Their Hudson Build server *two thumbs up for Continuous Integration* [http://bertram.netbeans.org/hudson/job/jdk7/]
Quick note: I call it a bug, Netbeans will call it a feature. When you start the beta release, it will autodetect your JDK 1.7 version (even if you have multiple version, I run 6 version and it grabbed the right one). However, it did not set the proper source/target version. To correct this, after creating a new project, select the "Files" tab. Open "project.properties" and scroll down to (in my release it was line: 39 and 40) and change the following lines from:
javac.source=1.5
javac.target=1.5
to
javac.source=1.7
javac.target=1.7
X== ... and there you go, welcome to the future of Java ==X
*Recommend* Here is a great deck that does a really good job covering the latest features: [JDK-7 Future Features]
Simple closure example taken from the deck listed above:
The old way of managing the Exceptions and closing streams:
public void copy(String src, String dest) throws IOException {
InputStream in = new FileInputStream(src);
try {
OutputStream out = new FileOutputStream(dest);
try {
byte[] buf = new byte[8 * 1024];
int n;
while ((n = in.read(buf)) >= 0)
out.write(buf, 0, n);
} finally {
out.close();
}
} finally {
in.close();
}
}
The JDK 7 way:
static void copy(String src, String dest) throws IOException {
try (InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dest)) {
byte[] buf = new byte[8192];
int n;
while ((n = in.read(buf)) >= 0)
out.write(buf, 0, n);
}
//in and out will 'automagically' close
}
No comments:
Post a Comment