So, it’s a bit surprising that compiler doesn’t ov...
# language-proposals
y
So, it’s a bit surprising that compiler doesn’t override the primary constructor with an invoke operator inside a companion object. It should at least give a warning or do not compile it at all...
Copy code
class Testo(
	val value: Int
) {
     companion object parse {
          operator fun invoke(value: Int): Testo {
              return Testo(value + 1);
          }
     }
}

fun main(args: Array<String>) {
    println(Testo(1).value)
}
So it’ll obviously print 1 and call primary constructor instead of the invoke() operator. I think this one should be considered as a small issue. Assigning invoke() operator for the companion object allows to build very neat factory methods. Just wondering: should I create an YouTrack Kotlin issue for this matter ?