Hi guys! Need some help to see if this is possible...
# announcements
a
Hi guys! Need some help to see if this is possible.
Copy code
class CustomKlass(val status: Int = 0,
                           val code: String? = null,
                           val message: String? = null,
                           val type: String? = null): ErrorResponse {

   
}
Is it possible to generate a function with the same parameters as this class (possibly at compile time) ?
s
“Generate”?
n
Use reflection + KotlinPoet maybe?
👍 1
a
@streetsofboston Yeah, I want to create a library function that can be customized depending on the params of a custom class like in the example.
@Max Russek I will try.
s
Ah… yup, then try what Max said. And, if you are veeeeery adventurous, try writing a Kotlin Compiler Plugin 🙂
n
sounds kind of xy problem to me though...do you reeeeally need that functionality? enough to spend at least a couple days implementing it?
👍 1
s
Also, Kotlin can refer to a constructor as a plain function:
val ctrAsFunction = ::CustomKlass
👍 2