Hey guys, got 2 questions about default values and...
# codereview
a
Hey guys, got 2 questions about default values and annotations. 1. Is there a way to get the default value of a parameter using reflection?
Copy code
data class Foo(val a: String = "hello")

// can I access "hello" somehow, like Foo::class.fields.map { it.defaultValue }
2. What’s the maximum supertype I can use on an annotation? I know annotations can only take certain values (primitives in Java, classes, etc.).
Copy code
@Target...
annotation class Bar<T>(val value: T)   // nope!

annotation class Bar(val value: Any)   // nope!
Is there some supertype for anything that is valid in an annotation?
I suspect the answer to 1 is “no, it’s not possible”. 2 I think there is some good pattern to use
b
In 1 you can create an instance of this data class with default values (but it's a bit tricky) and then iterate over it's properies