https://kotlinlang.org logo
#getting-started
Title
# getting-started
v

voohbar

02/22/2024, 9:56 PM
I need to be able to list all properties, including private superclass properties via Kotlin reflection:
Copy code
fun main() {

    abstract class Animal {
        private val name: String = "Jack" // removing "private" fixes it
    }

    class Dog : Animal() {
        private val age: Int = 3
    }

    Dog::class.memberProperties.size // = 1, "name" is missing
}
Am I missing something? Is there a way to do it?
If this was an intentional decision to not include them I find that pretty annoying since I can just use the Java reflection API…. So it’s not like this is improving any security.
y

Youssef Shoaib [MOD]

02/22/2024, 11:15 PM
There's an
allProperties
property I think. You need full jvm reflection though