No, it won’t create an instance of Git
, but it will create:
- The class of the companion object of
Git
. - The companion object of
Git
.
Creating the companion object class is way more expensive than creating the companion object itself. And I think there won’t be much performance difference between looking up the value using reflection without instantiating the companion object and just asking the instantiated companion object.
As there is no performance difference, I would keep it simple and just let the companion object of an implementation implement the descriptor interface. This has the added benefit that the code is easier to understand (this companion object is used as a descriptor) and navigate (which descriptor implementations are there):
class Git : {
companion object : VcsDescriptor {
override const val name = "Git"
}
}
Pseudocode to load a VCS descriptor:
val co = getObject("${vcsName}.companion object")
if (co is VcsDescriptor) {
register(co.name, co)
} else {
reportDescriptorError()
}