Java-style inner class

From foyono
Jump to navigationJump to search
>>> from foyndation import innerclass
>>>
>>> class X:
...
...     @innerclass
...     class Y:
...
...         def bar(self):
...             return self.foo # Y can access all fields of the enclosing instance of X.
...
...     def __init__(self, foo):
...         self.foo = foo
...
>>> x = X(100)
>>> y = x.Y()
>>> y.bar()
100