Hi Doug: Very interesting. Thank you for letting us now. This is indeed good news. It will fit nicely into Demeter/Java. Some change will be required to figure out the methods of the anonymous class so that you can generate efficient traversal code. The anonymous traversal will require an addition also. -- Karl From dougo@ccs.neu.edu Sun Nov 17 00:10:39 1996 Received: from nowhere (trix.ccs.neu.edu [129.10.112.38]) by amber.ccs.neu.edu (8.7.5/8.7.3) with SMTP id AAA29417 for ; Sun, 17 Nov 1996 00:10:17 -0500 (EST) Date: Sun, 17 Nov 1996 00:10:17 -0500 (EST) Message-Id: <199611170510.AAA29417@amber.ccs.neu.edu> Received: by nowhere (SMI-8.6/SMI-SVR4) id AAA03282; Sun, 17 Nov 1996 00:07:52 -0500 From: Doug Orleans To: demeter-seminar@ccs.neu.edu Subject: anonymous classes in JDK 1.1 X-Face: ,HWj@r1~8onbE_1x>uxU@3+pdQ>wXW.a:'$Q/`^aA0sh}!JxD8ueZ7vTwvvl]y*Ai9]`Wqd ^o[-r'u!3,@i>wCa Status: R I finally got around to looking at the proposal for "inner classes" (which includes anonymous classes) for the next version of the Java Development Kit, which is scheduled to come out first quarter of 1997. Here is an example of creating an anonymous class (and an instance of it) at run-time: Enumeration myEnumerate(Object array[]) { int count = 0; return new Enumeration() { public boolean hasMoreElements() { return count < array.length; } public Object nextElement() { return array[count++]; } }; } I think this is good news for Demeter, because it can makes visitor definition simpler: say we have a traversal "toY" defined on class X, and an abstract class (or interface) named "Visitor"; then we can say something like this: X x = X.parse(System.in); x.toY(new Visitor() { public void before(P host) { ... } public void before(Q host) { ... } public void after(Q host) { ... } }); (Or we could use "before P { ... }" syntactic sugar, if we want to extend Java's syntax.) This is mainly useful for one-shot visitors, of course; if the user wants a more complicated visitor that will be re-used in different traversals, he should still define it as a regular named class. But I think this make certain situations less awkward to express. Also, combined with run-time traversal definition (or "anonymous traversals"), it looks very similar to Crista's AP/S++ system: x.traverse(new Traversal("to Y"), new Visitor() { void before(P host) { ... } ... }); versus (traverse ((from x to (Y) ()) (before (P) ... ) ... )) --Doug