Hi, I would like to resolve the generic type of a property. Let's say I have the following code:
Copy code
public interface Base
public interface ExtendedBase: Base
public abstract class MyFlow<T> : Flow<T.() -> Unit>
public class MyFlow2<T : Base> : MyFlow<() -> T>() {
...
}
public class Container {
public val myFlow: MyFlow2<ExtendedBase>
}
I want to know the resolved type of the underlying flow i.e.
myFlow
is a flow that emits values of type
(() -> ExtendedBase).() -> Unit
(it is a
Flow<(() -> ExtendedBase).() -> Unit>
).
Are there any helper functions to get this information or would I have to write the code myself?
j
Jiaxiang
11/07/2022, 6:49 PM
you will have to write the code yourself, you can resolve the type of the property and you should be able to see the type arguments in the resolved type.
t
Thomas
11/08/2022, 7:54 AM
Thanks @Jiaxiang. Another question, kind of related. When I have something like
Flow<List<Int>>
are there any helper functions to get the complete generic argument i.e.
List<Int>
or do I have to resolve it myself?
j
Jiaxiang
11/08/2022, 8:55 PM
by getting the type argument of
Flow
you should be able to get
List<Int>
as a result?
t
Thomas
11/09/2022, 12:57 PM
I wasn’t clear enough, sorry. I want to have the type argument as a string without having to parse down the nested argument chain myself in order to construct the string. That is I would like to get "List<Map<Int, String.() -> Unit>" for a
Flow<List<Map<Int, String.() -> Unit>>
for example.
j
Jiaxiang
11/09/2022, 5:56 PM
we have builtin
toString
implementations, if it does not fit your use case, then you will have to write your own logics.
t
Thomas
11/11/2022, 9:15 AM
Ok. Thanks. Seems like I have to parse everything myself in order to get the complete string.