Java-style inner class

From foyono
Revision as of 19:07, 12 May 2025 by Shrovis-Bishopthorpe (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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