annotation class Plant
@Plant class Tree {
fun fertilize() {}
@get: OnGet
val color: String = "green"
@set: OnSet
var height: Int = 5
}
@Target(AnnotationTarget.PROPERTY_GETTER)
annotation class OnGet
@Target(AnnotationTarget.PROPERTY_SETTER)
annotation class OnSet
fun main() {
val classObj = Tree::class
for (annotation in classObj.annotations) {
println(annotation.annotationClass.simpleName)
}
classObj.findAnnotation<Plant>()?.apply {
println("Plant annotation is found on Tree class")
}
classObj.declaredMemberProperties.forEach {
println("Property Name = ${it.name}, annotation = ${it.annotations}")
println("Property Name = ${it.name}, getter = ${it.getter}, annotation = ${it.getter.annotations}")
}
}