12 Annotations and reflection

This chapter covers

  • Applying and defining annotations
  • Using reflection to introspect classes at run time
  • A real example of a Kotlin project

Up to this point, you’ve seen many features for working with classes and functions, but they all require you to specify the exact names of classes and functions you’re using as part of the program source code. To call a function, you need to know the class in which it was defined as well as its name and parameter types. Annotations and reflection give you the power to go beyond that and to write code that deals with arbitrary classes that aren’t known in advance. You can use annotations to add additional metadata and semantics to declarations. For example, you could use them ...

Get Kotlin in Action, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.