Changes between Version 143 and Version 144 of j2p


Ignore:
Timestamp:
10/10/24 12:18:39 (7 weeks ago)
Author:
wouter
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • j2p

    v143 v144  
    199199{{{@NonNull}}} is NOT inherited by subclasses. Therefore {{{@NonNull}}} has to be repeated in the derived classes.
    200200}}}
     201
     202=== @Defer
     203{{{@Defer}}} is a qualifier for Type specifications. The type that has this annotation is suggested to be imported later.  The translator will double quote such annotated types and suppress import of that class.
     204
     205For example, consider the cyclicref testcode in the core:
     206{{{
     207public class P {
     208        private @Defer Q q = null;
     209        public void join(@Defer Q q) {
     210                this.q = q;
     211        }
     212}
     213}}}
     214
     215The class Q that is referred from P refers back to Q. Without the @Defer annotations, class Q would have to be imported, resulting in a cyclic import. With the annotation however, the P class is translated as
     216{{{
     217class P:
     218 def join(self,q:"Optional[Q]") -> None:
     219  self.__q=q
     220 def __init__(self):
     221  self.__q:"Optional[Q]" = None
     222}}}
     223
     224This avoids the cyclic import, at the expense of some loss in python typing. Of course  the type checking is still done at the java side.
    201225
    202226