• a

    Ayfri

    9 months ago
    Hi, how can I get a list of
    KMutableProperty1<*, *>
    for the members of my class ? I only found
    memberProperties
    which returns a list of
    KProperty<*, *>
    and not castable so what should I use ?
    a
    r
    3 replies
    Copy to Clipboard
  • v79

    v79

    9 months ago
    If class
    Apple
    extends class
    Fruit
    , how can I create a map like
    mapOf<String,KClass<Fruit>>("apple" to Apple)
    ?
    v79
    e
    8 replies
    Copy to Clipboard
  • a

    aidanvii

    7 months ago
    Is it possible to check if a reified type is an inline/value class?
    a
    wrongwrong
    2 replies
    Copy to Clipboard
  • Dariusz Kuc

    Dariusz Kuc

    7 months ago
    Hello 👋 Just wondering if anyone knows how to detect whether given property is a lambda, e.g. given
    class Foo(val bar: () -> Bar)
    // or
    class Foo(val bar: suspend () -> Bar)
    how to check whether
    bar
    is actually a lambda. I was hoping that simple
    KProperty.returnType is Function<*>
    would do the trick, sadly that returns false...
    Dariusz Kuc
    e
    4 replies
    Copy to Clipboard
  • jean

    jean

    6 months ago
    Is there a way of doing something like this?
    fun test(json: JsonObject) {
        val type = String::class
        json.decode<type>() //error : Unresolved reference: type
    }
    
    private inline fun <reified T> JsonObject.decode(): T = Json.decodeFromJsonElement(this)
    jean
    e
    +1
    4 replies
    Copy to Clipboard
  • j

    Joe

    6 months ago
    What's the best way to get a
    Class
    instance in kotlin that is equal to
    void.class
    in java?
    Unit::class.java
    doesn't do it:
    >>> System.out::class.java.methods.first {it.name == "println"}.returnType == Unit::class.java
    res1: kotlin.Boolean = false
    (I'm using bytebuddy to dynamically generate a method and need it to be declared
    void
    to be used properly by some jersey code)
    j
    e
    3 replies
    Copy to Clipboard
  • jean

    jean

    6 months ago
    Is there a way to get the serialized name out of an enum value without using reflection? For now I’ve been doing this but I honestly don’t know if that’s a good thing to do
    enum class DeviceAttributeType {
        ...
        @SerializedName("waterOverflowIndication")
        WATER_OVERFLOW_INDICATION,
    
        @SerializedName("windowCoverLiftPercentage")
        WINDOW_COVER_LIFT_PERCENTAGE;
        ...
        override fun toString() = DeviceAttributeType::class.java
            .getField(name)
            .getAnnotation(SerializedName::class.java)
            ?.value ?: super.toString()
    }
    jean
    i
    +1
    5 replies
    Copy to Clipboard
  • lazt omen

    lazt omen

    4 months ago
    Is it possible to instantiate a data class with dynamic properties. Let's say I have this.
    data class Business(
        val id: Int,
        val name: String
    )
    
    val columns = listOf("id", "name")
    val values = listOf(1, "Hello")
    Is it possible to instantiate this class mapping dynamically my columns to contructor parameters?
    lazt omen
    e
    +1
    5 replies
    Copy to Clipboard
  • maxmello

    maxmello

    1 month ago
    How do I create an Array<T> (like Array<String>, Array<MyClass> etc.) from a List<T>, with the Array actually being the type T, not Array<Any?>? I’m inside an inline function with reified type parameter, so I should know the T KClass, but how do I dynamically create an Array<T>? I tried calling the Array constructor
    public inline constructor(size: Int, init: (Int) -> T)
    via reflection, but I don’t know how that second parameter is supposed to work.
    maxmello
    e
    +1
    6 replies
    Copy to Clipboard
  • j

    jw

    2 weeks ago
    is it possible to determine if a lambda type has a receiver or just a normal argument from parsing a function parameter's type? i'm in the process of switching from reflect to metadata-jvm (or maybe fully blown UAST) but looking for a quick workaround until then
    j
    e
    13 replies
    Copy to Clipboard