Changes between Version 164 and Version 165 of j2p


Ignore:
Timestamp:
11/14/24 09:59:07 (5 months ago)
Author:
wouter
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • j2p

    v164 v165  
    118118Note that that translated class will be in package p.a, rather than inside class p.A. Therefore this mechanism, has limited use in practice.
    119119
    120 Otherwise, no support is available. This includes anonymous inner classes. You can not import, call or use inner classes. This is for many reasons but the brief summary:
     120Otherwise, no support is available. So if you try to translate a class that has an inner class, the translator will fail. This includes anonymous inner classes.
     121
     122This is for many reasons but the brief summary:
    121123* The useful variant of inner class is the non-static inner class. This class can access fields in the enclosing class.
    122124* Python does not support accessing fields of the enclosing class unless some tricks are applied. But these tricks would break uniformity of constructors.
     
    129131
    130132===== Example workaround
     133The following is an example of the tricky case: an inner class that calls methods in the parent class.
    131134Java has the arrow notation (x,y) -> methodcall(x,y) to write lambda expressions.
    132 This notation can also be translated. This feature is especially useful when pulling inner classes out of a parent class, to pass parent class functions over to the pulled-out class.
     135This notation can also be translated. This feature is especially useful in the parent class to make references to methods the inner class needs.
    133136For example, suppose you have a class like this
    134137
     
    148151}}}
    149152
    150 The "new X" call has to be converted into an explicit class, but somehow it needs to be able to call f and g. We suggest to do it like this:
     153The "new X" call has to be converted into an explicit class, but somehow it needs to be able to call f and g in the Parent class. We suggest to do it like this:
    151154
    152155{{{