From: Kent Johnson <kent37@td...> - 2004-11-12 11:09:45
Why do you want them?
Many uses of Java inner classes - for callback functions - can be
replaced with lambdas, nested functions, or direct calls to member
functions. For example, I have a window class that creates a button.
When the button is pressed I want to call the addUserRole method of the
containing class. Here is the code to add the button:
self.addButton = JButton("Add user role", enabled=0,
actionPerformed = self.addUserRole)
addUserRole is an ordinary method of the window class:
def addUserRole(self, evt):
Here is code to set the windowClosing event of a frame to call sys.exit():
frame = StickyFrame(title, 'CategoryPanelTest', 600, 400,
windowClosing=lambda evt: sys.exit(0))
OK, I'll answer your question too :-)
You can put a class definition inside another class definition like this:
a = A()
n = a.makeN()
You could even put the class def'n inside a method of A if you only need
to create the classes in one place.
Tony Maniaci wrote:
> How do you implement Java inner classes in Jython?
> This SF.Net email is sponsored by:
> Sybase ASE Linux Express Edition - download now for FREE
> LinuxWorld Reader's Choice Award Winner for best database on Linux.
> Jython-users mailing list
Get latest updates about Open Source Projects, Conferences and News.