Private invocation annotation

It would be nice if there were an annotation that could mark a method as being protected for overrides, but private for invocation.

Use case:

class Component {

var propertiesValid = false

private fun validateProperties() {
if (propertiesValid) return
propertiesValid = true
updateProperties()
}

// Can override, but not invoke directly.
@privateInvoke protected open fun updateProperties() {
// Do work.
}

}

I think that even if the Kotlin compiler could enforce it, there still won’t be a Java counterpart. So either you can’t subclass in Java, or it will be exposed. I think both ways will be a no go.

I don’t mind if it’s not enforced at runtime, a compiler warning would be fine.

There would not be any compiler warning if you used such a class from Java code, because there’s nothing to warn about from Java’s point of view.