Java try-with-resources syntax irregularity

Viewed 2070

So I was looking through some of the new features of java 7, including the try-with-resources bit.

I understand how it works and everything, I just noticed that the syntax used to specify the resources is a little odd.

try 
    (InputStream fis = new FileInputStream(source);
        OutputStream fos = new FileOutputStream(target))
    {
            // stuff
        }
    }
    catch (Exception e) {
        // stuff
    }

Specifically the definition of resources:

try (InputStream fis = new FileInputStream(source);
        OutputStream fos = new FileOutputStream(target))

Is there any other place in java where separating statements within a parenthesis block is valid?

The only other time I can think of is a for loop

for ( ; ; )

but that's not quite the same since there has to be exactly 2 ;s, and statements are separated with a , 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 statements are ; delimited instead of , delimited? Is there even another comparable language that has a similar use of ; separated statements inside of a () block? I can't think of an example in java, C, or python.

2 Answers
Related