当前位置:网站首页>Kotlin annotations
Kotlin annotations
2022-08-08 20:32:00 【Don't forget the original intention of z】
Article table of contents
Annotations
Basic Notes
@JvaName
@JvaField
@JvnStatic
@JvmOverloads
@Throws
Meta annotation
Four Kotlin meta-annotations
@Target
Annotation classes corresponding to target annotations are kotlin.annotation.Target Specifies the applicable target of a new annotation
The allowedTargets attribute is used to set the applicable target, this property has 15 constants
@Retention
Retention period annotation, specifying the valid range of a new annotation
value attribute, which is used to set the retention period, there are three enumeration constants
@Repeatable
Repeatable annotation, which allows repeated annotations in the same program element, repeatable annotations must be annotated with this @Repeatable
@MustBeDocumented
Document annotations, which can decorate code elements (classes, interfaces, functions, properties, etc.), and document generation tools can extract these annotation information
Custom annotations
The simplest custom annotation code:
annotation calss annotation name declares annotation
annotation calss annotation name (val value: String') declares an annotation with attributes
annotation calss annotation name (valvalue: String = "annotation information") declares an annotation with a default value
The use of these custom annotations needs to be constrained with meta-annotations
Annotation target declaration
When multiple elements may be modified, you can use the annotation target declaration to specify the specific element modified by the annotation
Annotation target list
file file
property attribute, which is invisible in java using this target
field field
get getter accessor
set setter accessor
receiver extension function or function parameter
param constructor parameter
setparam setter accessor parameter
delegate save obsceneAttribute fields
Get annotation information through reflection
Get reflection instantiation
val clz = user::class
val ann = clz.findAnnotation get all annotation information
边栏推荐
猜你喜欢
随机推荐
梅科尔工作室OpenHarmony设备开发培训笔记-第一章学习笔记
PHP使用glob()查找文件
【翻译】用Argo CD揭开企业规模的持续交付的秘密成分
方舟建筑代码指令大全
PHPUnit 单元测试
OneNote 教程,如何在 OneNote 中检查拼写?
用 Antlr 重构脚本解释器
梅科尔工作室OpenHarmony设备开发培训笔记-第六章学习笔记
实践篇2:深度学习之----LetNet之tensorflow2的实现
如何用精益敏捷组合管理,提升研发效能?软件研发团队必看!
超人飞来!Flutter 实现满屏的力量感动画!
树查找(暑假每日一题 18)
方舟开服务器教程——开服配置常见问题及解决方法
LeetCode_67_二进制求和
What are the role of document management system for companies?
fillder4不间断提示the system proxy was change,看我解决
Kotlin中IO流
LeetCode #104.二叉树的最大深度
What are the latest developments in the handling of false information?KDD2022 "Fighting Misinformation and Responding to Media Bias" tutorial, 161 pages ppt
兼容并蓄广纳百川,Go lang1.18入门精炼教程,由白丁入鸿儒,go lang复合容器类型的声明和使用EP04