Annotations in Kotlin

Annotations, which are a form of metadata, provide data about a program that is not part of the program itself. Annotations can then be used by the compiler or by your own code via reflection at runtime. Depending on the annotation value, the meaning of the program or data can change.

Annotations have a number of uses, among them:

  • Information for the compiler — Annotations can be used by the compiler to detect errors or suppress warnings.
  • Compile-time and deployment- time processing — Software tools can process annotation information to generate code, XML files, and so forth.
  • Runtime processing — Some annotations are available to be examined at runtime.

There are certain annotations are present in both Java and kotlin as part of standard libraries. For example : @SuppressWarnings, @Override

Annotations syntax contain @ sign followed by annotations name, You can apply annotation for classes, functions, properties.

Kotlin enables the user to apply the annotation for files and expression as well, this feature is not present in Java and some other languages.

Annotations with constructor

To annotate the primary constructor, it is mandatory to mark the constructor with the constructor.

class Bucket @SomeAnnotations constructor(full:Boolean){
About Author :

I am Pavankumar, Having 8.5 years of experience currently working in Video/Live Analytics project.

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions