So, I was looking at some new features of java 7, including try-with-resources .
I understand how this works and that's it, I just noticed that the syntax used to specify resources is a bit strange.
try (InputStream fis = new FileInputStream(source); OutputStream fos = new FileOutputStream(target)) { // stuff } } catch (Exception e) { // stuff }
In particular, the definition of resources:
try (InputStream fis = new FileInputStream(source); OutputStream fos = new FileOutputStream(target))
Is there another place in java where the separation of statements inside a block of brackets really is?
The only time I can think of is a loop cycle
for ( ; ; )
but this is not quite the same, since there must be exactly 2 ; s, and the operators are separated using, as in
for (int i = 1, j = 100; i <= 100, j > 0; i = i-1, j = j-1)
So my question is: where did this syntax come from? Is there a reason the expressions are ; limited, not limited? Is there another comparable language that has a similar use ; separated statements inside a block () ? I can't come up with an example in java, C or python.
Falmarri
source share