Please: try-with-resouces Lock support!
Joe Darcy
joe.darcy at oracle.com
Sun Mar 6 15:52:26 PST 2011
Howard Lovatt wrote:
> You have a similar problem in C++:
>
> if ( x < y ) { ... }
>
> and
>
> if ( x < y > xy = 0 ) { ... }
>
> Some C++ compilers resolve this ambiguity by checking if x is a type
> or a variable. You could do the same with Java. However I am sure the
> Java guys no all this and therefore I am guessing that it isn't easy
> to do inside Javac. If Java didn't have separate name spaces for types
> it wouldn't be a problem, unfortunately Java didn't learn from Scheme
> :(
>
> You could allow:
>
> try ( variable ) { ... }
>
> Provided that variable was final or effectively final. That might be a
> nice compromise.
>
> -- Howard.
>
>
Yes, the changelog of the JSR 334 specification compared to its EDR has
contained the following sentences for a while:
> One potential future extension is to allow a resource to be specified
> as an expression that is a final or effectively final variable. Such a
> restricted expression form would remove the need to declare a resource
> variable for the sole purpose of aliasing an existing variable while
> avoiding pathologies stemming from the resource variable being
> modified within the body of the |try|-with-resources statement.
While this change is too late for JDK 7, it would be a fine refinement
to consider for JDK 8.
-Joe
More information about the coin-dev
mailing list