0

I'm trying to use Kotlin Reflection to generate JFrames from Classes with their members. I have created a couple Annotations, some of them are present at runtime and some are not.

Component Annotation:

@Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY)
@Retention(AnnotationRetention.RUNTIME)
annotation class Component(val constraints: String = "")

IsEnabled Annotation:

@Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY)
@Retention(AnnotationRetention.RUNTIME)
annotation class IsEnabled(val value: Boolean = true)

I'm using both of the Annotations like this:

class DisabledTest {
    @Component
    @IsEnabled(false)
    val btn = JButton("Should be Disabled")
}

If I run the following code:

DisabledTest::class.declaredMembers.forEach {
    println(it.name + ": " + it.annotations.map { a -> a.annotationClass.simpleName })
}

The only output I get is this: btn: [Component]

What is happening to the @IsEnabled Annotation because the Retention is set to AnnotationRetention.RUNTIME?

Marconymous
  • 11
  • 1
  • 1

1 Answers1

0

I reran the code multiple times again after doing some changes to the class DisabledTest, which don't have to do anything with the Annotations, and it just worked.

I have no idea why it is present at runtime now.

Marconymous
  • 11
  • 1
  • 1
  • Possibly an issue of previous runs using already built code and not properly rebuilding. Possibly the file wasn't actually saved when rebuilding. – undermark5 Jul 09 '22 at 17:29