Changes between Version 164 and Version 165 of j2p
- Timestamp:
- 11/14/24 09:59:07 (5 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
j2p
v164 v165 118 118 Note that that translated class will be in package p.a, rather than inside class p.A. Therefore this mechanism, has limited use in practice. 119 119 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: 120 Otherwise, 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 122 This is for many reasons but the brief summary: 121 123 * The useful variant of inner class is the non-static inner class. This class can access fields in the enclosing class. 122 124 * Python does not support accessing fields of the enclosing class unless some tricks are applied. But these tricks would break uniformity of constructors. … … 129 131 130 132 ===== Example workaround 133 The following is an example of the tricky case: an inner class that calls methods in the parent class. 131 134 Java 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.135 This notation can also be translated. This feature is especially useful in the parent class to make references to methods the inner class needs. 133 136 For example, suppose you have a class like this 134 137 … … 148 151 }}} 149 152 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:153 The "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: 151 154 152 155 {{{