| 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 | |
| 205 | For example, consider the cyclicref testcode in the core: |
| 206 | {{{ |
| 207 | public class P { |
| 208 | private @Defer Q q = null; |
| 209 | public void join(@Defer Q q) { |
| 210 | this.q = q; |
| 211 | } |
| 212 | } |
| 213 | }}} |
| 214 | |
| 215 | The 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 | {{{ |
| 217 | class 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 | |
| 224 | This 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. |