© Peter Späth 2019
Peter SpäthLearn Kotlin for Android Developmenthttps://doi.org/10.1007/978-1-4842-4467-8_14

14. Adding Hints: Annotations

Peter Späth1 
(1)
Leipzig, Germany
 
Annotations are for adding meta-information to your code. What does that mean? Consider the following classes:
class Adder {
    fun add(a:Double, b:Double) = a + b
}
class Subtractor {
    fun subtract(a:Double, b:Double) = a - b
}
If we have a larger arithmetic calculation project where the various operations get handled by classes like Adder and Subtractor here, we could have something like
val eng = CalculationEngine()
...
eng.registerAdder(Adder::class, "add") eng.registerSubtractor(Subtractor::class, "subtract")
...

for registering the particular low-level operations.

We could, however, ...

Get Learn Kotlin for Android Development: The Next Generation Language for Modern Android Apps Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.