Let's say I have the following code block:
int    version;
String content;
synchronized (foo) {
    version = foo.getVersion();
    content = foo.getContent();
}
// Do something with version and content
Its purpose is to grab a thread-safe consistent view of the version and content of some object foo.
Is there a way to write it more concisely to look more like this?
synchronized (foo) {
    int    version = foo.getVersion();
    String content = foo.getContent();
}
// Do something with version and content
The problem is that in this version the variables are defined in the scope of the (synchronized) curly braces and can therefore not be accessed outside of the block. So, the question is: Is there some way to mark these curly braces as not defining a new scope block or marking the variables as belonging to the parent scope without having to declare them there?
(Note: I do not want to simply pull the // Do something with version and content into the synchronized block.)
 
     
     
    