https://kotlinlang.org logo
Title
x

xenoterracide

01/24/2019, 8:57 PM
how can I get the value of a field, when I only know the name of the field (as a string)? I don’t see an example in https://kotlinlang.org/docs/reference/reflection.html
@ParameterizedTest
    @ValueSource(strings = [ "emr", "packet_100hz", "packet_1hz" ])
    fun channel( channel: String ) {
        assertThat( Channel::class.java ).hasPublicFields( channel.toUpperCase() + "_NEW" )
        assertThat( Channel::`channel`.get() ).isEqualTo( channel + ".new" )
    }
d

Davide Giuseppe Farella

01/24/2019, 11:07 PM
kClass.members.find { it.name == knownName }
👍 1