https://kotlinlang.org logo
Title
d

Dennis Schröder

03/14/2019, 2:13 PM
User.find {
            Users[fieldName] eq fieldName
        }.firstOrNull()
I am using Kotlin Expose DAO Model! And Iam trying to buld a generic query to query for the fieldName by pasing it in. How can I do this? I mean, how can I access the field from
Users
by a variable?
k

karelpeeters

03/14/2019, 6:57 PM
Do you wont to access a class property by (string) name?
That's going to need reflection: https://stackoverflow.com/a/35539628/5517612
d

Dennis Schröder

03/15/2019, 8:56 AM
OK Thanks für the replies. Reflection is not a good choice as I wan´t to avoid reflection in business logic
k

karelpeeters

03/15/2019, 12:17 PM
You want to avoid reflection because it's unsafe? In the end your problem is inherently unsafe.
d

Dennis Schröder

03/15/2019, 1:27 PM
Well not if I can make it typesafe!
k

karelpeeters

03/15/2019, 1:28 PM
If you want to index by String you can never make it type safe.
d

Dennis Schröder

03/15/2019, 2:34 PM
You are right! I was wrong! Still thinking too much in a dynamic typed way where I come from!