[摘译] Kotlin中的注解和Python的装饰器有何区别? (Is Python decorators available in Kotlin?)
简译文
尽管Kotlin的注解和Python装饰器类似使用@
符号,但Kotlin的注解远不如Python装饰器灵活,他只能用来给代码添加一些信息,不能包含任何可执行的代码。
一些注解可能对编译过程有影响(取决于编译器),但用户自定义的的注解一般只用来提供信息。
原文
项目 | 内容 |
---|---|
作者Author | Aasmund Eldhuset, Khan Academy |
链接Link | https://github.com/Khan/kotlin-for-python-developers |
许可License | CC BY-NC-SA 3.0 US |
While Kotlin annotations look like Python decorators, they are far less flexible: they can generally only be used for metadata. They are pure data-containing classes, and do not contain any executable code. Some built-in annotations have an effect on the compilation process (such as @JvmStatic), but custom annotations are only useful for providing metadata that can be inspected at runtime by the reflection system
This material was written by Aasmund Eldhuset; it is owned by Khan Academy and licensed for use under CC BY-NC-SA 3.0 US.