[2244] in java-interest
Nested Classes and Nested Methods
daemon@ATHENA.MIT.EDU (John D. Ramsdell)
Wed Sep 27 09:28:55 1995
To: java-interest@java.sun.com
cc: ramsdell@linus.mitre.org
Date: Wed, 27 Sep 1995 07:03:37 -0400
From: "John D. Ramsdell" <ramsdell@linus.mitre.org>
I've noticed that C++ allows class declarations within a class or a
method, while the Java syntax diagrams forbid this. Nested classes
seem to be useful for local classes used within an implementation.
For example, a package for manipulating sets might declare a local
class for manipulating the elements of a set as a list. Defining the
list class as a nested class means that dynamic linking need not be
used to resolve references to the list class from the methods of the
set class, and therefore opens new possibilities for code
optimization. Futhermore, sometimes one does not want to allow
dynamic redefinitions.
Block structured languages, such as Algol, Pascal, Modular, Ada, and
Scheme, allow nested procedures, or procedures defined within
procedures. Support for nested function definitions is one of the
extensions provided by the GNU C compiler. In Java like syntax, a
nested method declaration might look like:
class ... {
double sumsqr(double a, double b) {
double sqr(double x) { return x * x; }
return sqr(a) + sqr(b);
}
}
Nested methods can be used to write procedures that pass information
through the enclosing environment rather than via parameter passing.
Nesting was in in the `60s; Is it out in the `90s?
Just some food for thought...
John
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com