If Java Were Designed Today - The Synchronizable Interface - DZone Java
So, in order for a given language feature to work, the Java language imposes constraints on the types that are used in that context. In the case of for each or try-with-resources, a concrete JDK type is required. In the case of lambda expressions, a matching structural type is required (which is rather esoteric but clever, for Java).
Unfortunately, for backwards-compatibility reasons, there will not be any new restriction added for synchronized
blocks. Or will there? It would be great, and an optional warning could be issued if the type is not Synchronizable
. This might allow, in the course of a couple of future major releases, to remove monitors from objects that are not really required to be synchronizable.
Which is essentially what the C language has been doing with mutexes all along. They're a special thing. Not the common thing.
Read full article from If Java Were Designed Today - The Synchronizable Interface - DZone Java
No comments:
Post a Comment