Kotlin's annotation functionality enables programmers to incorporate extra information directly into source files. However, the program's actions remain unchanged as a result of this information. Several tools use this data for deployment as well as development of Mobile application.
Applying Annotation
We can use annotation by prefixing its name with the @ sign in front of a code element. For example, if we wish to use an annotation named Positive, we should write the following:
A parameter can be passed in parenthesis function call.
We should return the @ sign. We have supplied the Replacewith() annotation as an argument.
When an annotation parameter is a class object, we must add::class to the class name as follows:
Declaring Annotation
Code cannot be included in annotation declarations. When declaring custom annotations, we should describe which code components they may apply to and where they should be saved.
an annotation that requires parameter mentioned below
Annotate a constructor
We can also annotate the constructor of a class.
Annotate a property
We can annotate the properties of the class by adding an annotation to them.
Example
Output