https://kotlinlang.org logo
e

eygraber

09/02/2020, 8:45 PM
Is there any way to get a method reference to a constructor when accessing it through a FQN? i.e.
::kotlinx.serialization.json.JsonObject
throws a compiler error
n

nanodeath

09/02/2020, 9:02 PM
I don't think the constructor "method" is one you can directly refer to in code, is it? even in Java
e

eygraber

09/02/2020, 9:04 PM
If I do it without a FQN it works i.e.
::JsonObject
does it need to be FQN?
e

eygraber

09/02/2020, 9:40 PM
Yes, because of clashes, but I found some documentation in KotlinPoet that mentions this and says to use import aliases
n

nanodeath

09/02/2020, 9:42 PM
that's what I was going to suggest 🙂 import aliases are handy.
that said...it's surprising that
::
and FQNs seem not to play well together
e

ephemient

09/02/2020, 10:17 PM
.
binds stronger than
::
try
kotlinx.serialization.json::JsonObject
n

nanodeath

09/02/2020, 10:19 PM
I tried that and
::(the.Class)
and neither works :|