Sponsored Link •
|
Summary
One of the key differences between the different Java inner class and closure proposals is the lexical scope of names, this blog compares the scoping of the major proposals (CICE + ARM, C3S, FCM + JCA, and BGGA in both its forms)
Advertisement
|
One of the key differences between the different Java inner class and closure proposals is the lexical scope of names, this blog compares the scoping of the major proposals (CICE + ARM, C3S, FCM + JCA, and BGGA in both its forms). The order in the comparison table below, from left to right, is how large a change is made to Java. There are two main change groups: CICE and C3S do not change the semantics of inner class methods, whereas FCM and BGGA do. All the proposals add syntactic changes to make the declaration of inner classes shorter. The comparison is similar to that given by Stephen Colebourne in his blog, but includes the inherited scope as well as the enclosing scope. (Stephen Colebourne was going to post the table below, or at least a similar one, on his blog but was travelling at the time.)
A more detailed comparison was given in a previous post, but the table below is a good summary of an important difference (lexical scope).
Property |
Inner class |
|||||||
Access to names from enclosing scope |
Y (Local variables must be final) |
Y (Local variables must be public to give write access) |
Y |
Y |
Y |
Y |
Y (Local variables must be final) |
Y |
Access to names from inherited classes/interfaces |
Y |
Y |
N (No inheritance) |
Y |
N |
N |
N |
N |
Inherited names hide enclosing names |
Y |
Y |
N (No inheritance) |
Y |
N |
N |
N |
N |
Break and continue into the enclosing scope from within the inner class/closure method |
N |
N |
Y (No inheritance) |
Y (Must be a labelled break or continue to break or continue into the enclosing method) |
N |
Y |
N |
Y |
Return from the enclosing method (as opposed to returning from the inner class/closure method) |
N |
N |
Y (No inheritance) |
Y (Must be qualified with method name to return from the enclosing method) |
N |
Y |
N (Can only return via going of the end of the code block – no return statement allowed) |
Y (Return statement returns from the enclosing method and going of the end of a code block returns from the inner class/closure method) |
Have an opinion? Readers have already posted 23 comments about this weblog entry. Why not add yours?
If you'd like to be notified whenever Howard Lovatt adds a new entry to his weblog, subscribe to his RSS feed.
Dr. Howard Lovatt is a senior scientist with CSIRO, an Australian government owned research organization, and is the creator of the Pattern Enforcing Compiler (PEC) for Java. PEC is an extended Java compiler that allows Software Design Patterns to be declared and hence checked by the compiler. PEC forms the basis of Howard's 2nd PhD, his first concerned the design of Switched Reluctance Motors. |
Sponsored Links
|