I have a private constructor for my class and implemented invoke on a companion object for a kind of "generic constructor"
class Test private constructor(className: String) {
companion object {
internal inline operator fun <reified T> invoke(): Test {
return Test(T::class.java.name)
}
}
}
and I can even have a public built-in function that calls this common constructor
public inline fun test() = Test<Any>()
doesn't mean that every invokation test()expands to Test(Any::class.java.name), although this constructor is private?
So my questions are:
- Why
internal inline funcan this one call a private constructor? (public pleasure could not) - Why does this function
public inline funcall an internal function? - And why can I end up opening a private constructor in
public inline fun?
source
share