Traditional "for" (first example) and ARM "try" (last example) support local
variable declarations that are scoped to the statement. In light of the
upcoming "instanceof" enhancement in Java, I was thinking about possible
alternatives for declaring local variables that have statement scope.
for (int i = ...; ...) {
// i available
}
// i unavailable
for (x in y index i) { // from Gosu (http://gosu-lang.github.io/docs.html) --
an alternative to using eachWithIndex
}
if (x instanceof T t) { // from Java 14+
}
if (def x = ...) { // tests Groovy truth in this form; may be wrapped in parens
to check something else about "x"
}
try (def ac = ...) {
}
This e-mail is for the sole use of the intended recipient and contains
information that may be privileged and/or confidential. If you are not an
intended recipient, please notify the sender by return e-mail and delete this
e-mail and any attachments. Certain required legal entity disclosures can be
accessed on our website:
https://www.thomsonreuters.com/en/resources/disclosures.html