https://kotlinlang.org logo
#announcements
Title
# announcements
m

marcoferrer

05/31/2017, 8:40 PM
I tried asking in the reflect channel and couldn’t get a response. It might be a dumb question but I figured I would ask here. Which of these approaches would be the most performant way of finding a constructor of a generic that takes an argument that is a subclass of type ‘Item’
Copy code
T::class.constructors.find {
       it.parameters.size == 1 &&
       it.parameters[0].type.isSubtypeOf(Item::class.createType())
}
    
T::class.constructors.find {
        it.parameters.size == 1 &&
        it.parameters[0].type.jvmErasure.isSubclassOf(Item::class)
}
i

Ian

05/31/2017, 10:31 PM
gorgamore: At the risk of stating the obvious, it might be easier just to benchmark it 🙂
m

marcoferrer

06/01/2017, 2:02 PM
@Ian I think you're right. Sometimes it's best to just do the obvious lol. Thx
2 Views