TWiki . Dev . InnerClasses

I was wondering if it will sometime be possible to declare inner classes in Nice ? I guess this is very useful in some cases. Inner classes are currently not accepted by the compiler. So I think the inner classes are not even planned ? (I come to this conclusion since public and private are in the list, but also not yet implemented, or am I wrong ?)

-- GamsL - 24 Jul 2002

Inner classes are one of these feature of which I am not sure if they would add anything to Nice. In this case my policy is to wait, work on what is surely useful, and listen to arguments. They are definitely in Java, but Java has no anonymous functions (which are faked by anonymous inner classes), and is class centric, so that it is useful to put a class inside another. Are there arguments to say that Nice misses them?

Actually inner classes in Java are compiled to normal classes, which have a link to their container class (roughly, I think there are visibility issues). Which gives a hint at what to do if you really miss one.

-- DanielBonniot - 25 Jul 2002

I find I use inner classes in Java quite often, usually when writing classes that need to work together closely and to avoid polluting the public interface or resorting to package access. The way I see it, inner classes are a combination of two features. The first is the automatic parent reference. While nice, this is just syntactic sugar and can be completely simulated in other ways. The second is the access granted to the private members of the parent class. This is essentially the same as using the friend keyword from C++, and as far as I know cannot be simulated in any other way in Java (beyond reflection, perhaps).

What I'd rather see in Nice though is something like the way Eiffel does access control. Every feature of a class in Eiffel can have a list of classes who (along with their subclasses) can see the feature. For example, the equivalent of protected access could be achieved by listing the class itself. A language feature like this allows classes to co-ordinate with each other at a very fine-grained level, rather than resorting to the big hammer of package access or the dangerous friend concept.

-- Vulcannis - 21 Aug 2003

Nice allows multiple classes in a single sourcefile. VisibilityModifiers are not implemented yet but the proposal is to give sourcefile access to things with the private modifier. So it will be possible to simulate the access restrictions as in java inner classes. Details of the access modifiers aren't decided yet.

-- ArjanB - 21 Aug 2003

----- Revision r1.3 - 21 Aug 2003 - 19:47 GMT - ArjanB
Copyright © 1999-2003 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback.